python - 在 python urllib.urlretrieve 中设置推荐 url

标签 python html

我在 Python 中使用 urllib.urlretrieve 下载网站。尽管某些网站似乎不希望我下载它们,除非他们从自己的站点获得了适当的引荐来源网址。有谁知道我可以在 Python 的一个库或外部库中设置引荐来源网址的方法。

最佳答案

import urllib2
req = urllib2.Request('http://www.example.com/')
req.add_header('Referer', 'http://www.python.org/')
r = urllib2.urlopen(req)

采用自 http://docs.python.org/library/urllib2.html

关于python - 在 python urllib.urlretrieve 中设置推荐 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2098623/

相关文章:

python文件逐行读取并检查条件,如果不为真则等待其为真而不跳过该行

python - IndexError : too many indices. 1 行 2 列的 Numpy 数组

python - 我的 for 循环没有按预期工作

html - 1px x 1px inline-block div,不需要的间距

javascript - jQuery 正则表达式选择器插件不工作

python - float 限制

python - DataFrame.describe 方法忽略某些列

html - 我怎样才能居中一个div

html - Nokogiri 能否将无序列表视为段落?

html - 使用 css 或 html 的动态视频/图像样式