我在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

07-24 09:38
查看更多