View Single Post
Old 03-13-2010, 05:42 PM   #8
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by kovidgoyal View Post
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.

Last edited by Starson17; 03-13-2010 at 06:33 PM.
Starson17 is offline   Reply With Quote