一直感觉 baidu baike不错
每次 查个什么东西 一般都去百度baike 不过很烦 每次都要打开浏览器
我知道 有个 w3m 终端下的浏览器(这个 真的太强大了)
关于网络方面的脚本我一窍不通 只会写点简单的本机脚本玩下
各位大大 能否帮小弟一把 不胜感激
我就知道个 wget呵呵
能够这样就OK了
./baike.sh michael jackson
然后就可以把内容显示到终端 或者 存进 一个文本中
最好能向 w3m -dump URL | cat - > URL.txt 那样的文本效果(也就是按照网页内容格式的文本)
想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
- 543082593
- 帖子: 234
- 注册时间: 2008-11-07 8:41
想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
- xzap
- 帖子: 256
- 注册时间: 2006-08-24 21:25
Re: 想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
我是菜鸟,我不会,等着高手来解答
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
Re: 想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
看懂干嘛。用就是了。● baike.pl w3m
实际链接:http://baike.baidu.com/view/455886.htm
w3m浏览百度首页
w3m是个开放源代码的文字式网页浏览器。
w3m支援表格、框架、SSL连线、颜色。如果是在适当的terminal上,甚至还支援“inlineimage”。这个软件通常尽量呈现出网页本来的编排。
“w3m”这名字是来自“WWW-wo-Miru”,就是日文的“看WWW”之义。
● 鸣学
- O_O_BOT
- 帖子: 2461
- 注册时间: 2009-05-20 19:32
Re: 想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
wget grep awk 就是了
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
- xzap
- 帖子: 256
- 注册时间: 2006-08-24 21:25
Re: 想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
果然有高手,不过都回答的不详细啊。我来说下自己的想法
1、将要查询的词条用od转码
2、用搜索词条功能查找词条 wget http://baike.baidu.com/w?ct=17&lm=0&tn= ... mit=search
3、根据上面wget 下来的信息用grep来判断是否存在这样的词条,不存在的时候百度会显示“百度百科尚未收录词条”这样就可以直接输出不存在词条的信息。也可以推送第一条最接近的。
4、如果存在那基本就是第一条,用grep sed awk 把链接截取出来再wget就可以了
5、对wget下来的内容格式进行处理便于输出
6、完工
1、将要查询的词条用od转码
2、用搜索词条功能查找词条 wget http://baike.baidu.com/w?ct=17&lm=0&tn= ... mit=search
3、根据上面wget 下来的信息用grep来判断是否存在这样的词条,不存在的时候百度会显示“百度百科尚未收录词条”这样就可以直接输出不存在词条的信息。也可以推送第一条最接近的。
4、如果存在那基本就是第一条,用grep sed awk 把链接截取出来再wget就可以了
5、对wget下来的内容格式进行处理便于输出
6、完工
- oneleaf
- 论坛管理员
- 帖子: 10441
- 注册时间: 2005-03-27 0:06
- 系统: Ubuntu 12.04
-
- 帖子: 18311
- 注册时间: 2008-01-09 22:41
- 543082593
- 帖子: 234
- 注册时间: 2008-11-07 8:41
Re: 想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
这个确实行oneleaf 写了:w3m "http://baike.baidu.com/searchword/?word ... kson&pic=1"
汗啊 不过 为什么 在浏览器中
输入 http://baike.baidu.com/searchword/?word ... n&pic=1的时候 它直接跳转了
http://baike.baidu.com/view/4039.htm
也就是 http://baike.baidu.com/searchword/?word ... kson&pic=1 你是怎么知道的 ?
who can tell me?
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
- 543082593
- 帖子: 234
- 注册时间: 2008-11-07 8:41
Re: 想写个SHELL脚本 来获取 百度百科 (ee那个 perl的看不懂 )
呵呵 参考 以上各位的
更改了一下 终于实现了百度百科的功能 呵呵 谢谢了
下面 分享一下下 (很简陋)
主要是 searchword中如果是 如果参数中有空格的话 比如 good study good time 那么在searchword中就是这种形式才行 good+study+good+time
还有 如果输入中文的时候 用到了 uni2ascii(这个是参照 ee的那个perl脚本中的 THX)
thx各位
使用的时候 比如想百科下 周杰伦 ./baike.sh 周杰伦
还有一点要注意的是 参数中 特殊字符的问题
比如 我注意到 ./baike.sh they don't care about us
这里有问题了 不会得到结果 这是因为 don't中的 ' 是个特殊字符 要转义
这样就OK了 ./baike.sh they don\'t care about us
更改了一下 终于实现了百度百科的功能 呵呵 谢谢了
下面 分享一下下 (很简陋)
代码: 全选
#!/bin/bash
#echo "$@" | sed 's# #+#g'
searchword=`echo $* | sed 's# #+#g'`
searchword=`echo "$searchword" | iconv -f utf8 -t gbk | uni2ascii -a J`
URL="http://baike.baidu.com/searchword/?word="$searchword"&pic=1"
w3m -no-cookie $URL
还有 如果输入中文的时候 用到了 uni2ascii(这个是参照 ee的那个perl脚本中的 THX)
thx各位
使用的时候 比如想百科下 周杰伦 ./baike.sh 周杰伦
还有一点要注意的是 参数中 特殊字符的问题
比如 我注意到 ./baike.sh they don't care about us
这里有问题了 不会得到结果 这是因为 don't中的 ' 是个特殊字符 要转义
这样就OK了 ./baike.sh they don\'t care about us
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER