即使机器人关闭,Wget 也会重定向
Wget redirects even though robots are off
我正在使用 wget 为极右翼极端主义研究项目下载数据。我有一个 url 的列表,但是没有下载 url。 (它们确实在浏览器中工作。)
url的结构都是这样的:
https://www.forum.org/forum/printthread.php?t=1182735&pp=100
但是 wget 重定向到首页。然而,这些 urls 与 wget 一起工作得很好:
https://www.forum.org/forum/printthread.php?t=1182735
问题好像是url、&pp=100
的最后一点。
到目前为止我尝试过的事情:
- 转义
&
字符 (\&
) 或将其替换为 %
或 %20
.
- 关闭机器人。
这是我使用的 wget 代码:
cat urls.txt | parallel -j 4 wget -e robots=off --no-check-certificate --auth-no-challenge --load-cookies cookies.txt --keep-session-cookies --random-wait --max-redirect=0 -P forumfiles -a wget_log_15dec2018
编辑:为了它的价值,urls 使用 HTTrack 下载。这让我对这个 wget 问题更加好奇。
Edit2:为匿名更改了原始 urls。
Edit3:感谢下面的回答,以下代码有效:
cat urls.txt | parallel -j 4 wget --no-check-certificate --auth-no-challenge --load-cookies cookies.txt -nc --keep-session-cookies -U "Mozilla/5.0" --random-wait --max-redirect=0 -P forumfiles -a wget_log_17dec2018
有趣的是,您提供的网站示例 returns 基于 user-agent
字符串的结果。使用默认用户代理,服务器 returns 301 响应并要求 wget 仅下载第一页。
您只需更改用户代理字符串即可使其正常工作。例如。:
--user-agent=mozilla
我正在使用 wget 为极右翼极端主义研究项目下载数据。我有一个 url 的列表,但是没有下载 url。 (它们确实在浏览器中工作。)
url的结构都是这样的:
https://www.forum.org/forum/printthread.php?t=1182735&pp=100
但是 wget 重定向到首页。然而,这些 urls 与 wget 一起工作得很好:
https://www.forum.org/forum/printthread.php?t=1182735
问题好像是url、&pp=100
的最后一点。
到目前为止我尝试过的事情:
- 转义
&
字符 (\&
) 或将其替换为%
或%20
. - 关闭机器人。
这是我使用的 wget 代码:
cat urls.txt | parallel -j 4 wget -e robots=off --no-check-certificate --auth-no-challenge --load-cookies cookies.txt --keep-session-cookies --random-wait --max-redirect=0 -P forumfiles -a wget_log_15dec2018
编辑:为了它的价值,urls 使用 HTTrack 下载。这让我对这个 wget 问题更加好奇。
Edit2:为匿名更改了原始 urls。
Edit3:感谢下面的回答,以下代码有效:
cat urls.txt | parallel -j 4 wget --no-check-certificate --auth-no-challenge --load-cookies cookies.txt -nc --keep-session-cookies -U "Mozilla/5.0" --random-wait --max-redirect=0 -P forumfiles -a wget_log_17dec2018
有趣的是,您提供的网站示例 returns 基于 user-agent
字符串的结果。使用默认用户代理,服务器 returns 301 响应并要求 wget 仅下载第一页。
您只需更改用户代理字符串即可使其正常工作。例如。:
--user-agent=mozilla