我正在使用mechanize在python中编写脚本。我正在关注一个链接:
br = mechanize.Browser()
br.open("http://www.neopets.com/browseshop.phtml?owner=nick_291540")
#returns last link
for link in br.links(url_regex="buy_item.phtml"):
placeholder = 1
br.follow_link(link)
我想假装我被定向到某个网址的链接。我该怎么做?
答案 0 :(得分:2)
您可以设置Referer
标题,例如docs:
import mechanize
req = mechanize.Request("http://foobar.com/")
req.add_header("Referer", "http://wwwsearch.sourceforge.net/mechanize/")
r = mechanize.urlopen(req)