指定重定向页面以单击链接

时间:2013-09-07 18:22:33

标签: python http browser request mechanize

我正在使用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)

我想假装我被定向到某个网址的链接。我该怎么做?

1 个答案:

答案 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)