1

I'm writing a script in python, using mechanize. I'm following a link:

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)

I want to pretend that I'm being directed to the link from a certain url. How do I do this?

4

1 回答 1

2

您可以设置Referer标题,例如来自docs

import mechanize
req = mechanize.Request("http://foobar.com/")
req.add_header("Referer", "http://wwwsearch.sourceforge.net/mechanize/")
r = mechanize.urlopen(req)
于 2013-09-07T18:32:33.810 回答