Quote:
Originally Posted by kovidgoyal
One possibility is to monkey path the open_novisit method on the browser instance to send the required referrer. so something like this
Code:
def get_browser(self):
br = BasicNewsRecipe.get_browser(self)
orig_open_novisit = br.open_novisit
def my_open_no_visit(self, url, **kwargs):
data = # add the referrer to the header
return orig_open_novisit(url, data=data)
br.open_novisit = my_open_no_visit
return br
|
Thanks. I could never have solved this without your pseudocode tip. It still took a while to figure out, but it was fun. The line:
def my_open_no_visit(self, url, **kwargs):
had to be changed to:
def my_open_no_visit(url, **kwargs):
(complaints about number of arguments),
and the lines:
data = # add the referrer to the header
return orig_open_novisit(url, data=data)
were changed to :
req = mechanize.Request(url, headers = {'Referer':'http://referer_site.com/'})
return orig_open_novisit(req)
At least I got a chance to learn a bit more about mechanize. Thanks again for the tip, and enjoy your return home.