【发布时间】:2009-07-14 23:10:38
【问题描述】:
我受到另一个问题的启发,写了一个脚本(或者更确切地说是一个单行)来抓取随机的 Wikipedia 页面。
这是我目前所得到的:
# Grab the HTTP header response from Wikipedia's random page link
curl 'http://en.wikipedia.org/wiki/Special:Random' -sI
# Search STDIN for the Location header and grab its content
perl -wnl -e '/Location: (.*)/ and print $1;'
这很有效。它向控制台输出一个随机的 Wikipedia URL。但我需要在该 url 上附加“?printable=yes”才能获得没有所有非文章内容的维基百科页面。
但是,运行:
curl 'http://en.wikipedia.org/wiki/Special:Random' -sI | perl -wnl -e '/Location: (.*)/ and print $1 . "?printable=yes";'
输出: ?printable=yespedia.org/wiki/James_Keene_(footballer)
为什么我的串联没有串联?
更新:
对于好奇的人,这里是完成的单行:
curl `curl 'http://en.wikipedia.org/wiki/Special:Random' -sI | perl -wnl -e '/Location: ([^\r]*)/ and print $1 . "?printable=yes";'`
【问题讨论】:
-
请将标题改写成更有意义的内容。
-
我愿意接受建议。