Re: urllib - changing the user agent
From: Samuel Walters (swalters_usenet_at_yahoo.com)
Date: 01/09/04
- Next message: Krzysztof Stachlewski: "Re: Python is far from a top performer according to benchmark test..."
- Previous message: ian: "Re: Variable Scope 2 -- Thanks for 1."
- In reply to: John J. Lee: "Re: urllib - changing the user agent"
- Next in thread: John J. Lee: "Re: urllib - changing the user agent"
- Reply: John J. Lee: "Re: urllib - changing the user agent"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 09 Jan 2004 21:17:24 GMT
|Thus Spake John J. Lee On the now historical date of Fri, 09 Jan 2004
20:16:54 +0000|
> or again, you can set .addheaders on OpenerDirector (which will cause
> those headers to be added to all requests).
This, however, does not stop the original User-agent header to be sent,
and google still filters out the request. Instead, it just causes a
second user-agent to be sent.
Here is the very bad code I used to solve this problem. There are better
ways, I assure you, but it should point you in the right direction. You
should probably do this with inheritance, but for my quick script, this is
what I did.
----
#Override the default OpenerDirector Class Init.
#OpenerDirector *insists* on adding a User-Agent
#That some websites don't like.
foo = OpenerDirector.__init__
def bar(self, Agent='None'):
foo(self)
self.addheaders = [('User-Agent',Agent)]
OpenerDirector.__init__ = bar
-----
HTH
Sam Walters.
--
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
Do you really want to go there?"""
- Next message: Krzysztof Stachlewski: "Re: Python is far from a top performer according to benchmark test..."
- Previous message: ian: "Re: Variable Scope 2 -- Thanks for 1."
- In reply to: John J. Lee: "Re: urllib - changing the user agent"
- Next in thread: John J. Lee: "Re: urllib - changing the user agent"
- Reply: John J. Lee: "Re: urllib - changing the user agent"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|