命令行参数问题

命令行参数问题

我有一个名为 test.sh 的 bash 脚本,它的当前脚本是:

url=
lynx -dump $url > story.txt
echo "step one completed"

./test.sh http://www.fox.com除了我运行或任何网站时,story.txt 都会显示:

                            Forbidden
   You don't have permission to access / on this server.

我该如何修复它,以便当我打开 story.txt 时,它会显示 url 的实际转储?

答案1

您的脚本对我来说不起作用,但我想它对您有用,所以我们可能有不同的设置。我将脚本更改为

lynx -dump $1 > story.txt
echo "step one completed"

我用它运行

 ./test.sh http://www.techland.ro

我得到了相同的结果。

不要使用 fox.com 运行脚本,而是尝试使用 techland.ro,你会发现脚本实际上运行得很好。问题不在于你的脚本,而在于你试图访问的网站。我相信它会阻止网站爬虫,因为 lynx 是一个命令行浏览器,它实际上就像一个爬虫一样,导致你收到消息。

您可以为网站设置不同的规则,如果某个网站阻止未知爬虫,那么它也可能阻止 lynx(或任何其他命令行浏览器)。您的脚本没有问题,是网站阻止了您。

答案2

该 URL 也出现错误curl

curl -i http://www.fox.com/
HTTP/1.1 403 Forbidden
Server: AkamaiGHost
Mime-Version: 1.0
Content-Type: text/html
Content-Length: 260
Cache-Control: max-age=3600
Date: Thu, 06 Dec 2012 20:17:17 GMT
Connection: close

<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>

You don't have permission to access "http&#58;&#47;&#47;www&#46;fox&#46;com&#47;" on this server.<P>
Reference&#32;&#35;18&#46;2fa2f5cc&#46;1354825037&#46;8323a81
</BODY>
</HTML>

显然该网站正在进行一些奇怪的用户代理嗅探。传递 Firefox 用户代理似乎有效:

curl -i -A 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0) Gecko/17.0 Firefox/17.0' http://www.fox.com/
HTTP/1.1 200 OK
Server: Apache
Content-Length: 70647
Content-Type: text/html; charset=utf-8
X-FarmName: www.fox.com
X-FarmAddr: 10.96.57.103
Cache-Control: max-age=3600
Date: Thu, 06 Dec 2012 20:22:58 GMT
Connection: keep-alive

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:tp="http://player.theplatform.com/" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml" >
<head>
        <title>FOX Broadcasting Company - FOX Television Shows</title>

相关内容