python changing headers
how do i change my headers and request so that i appear as firefox ...
like when reque开发者_开发问答st to some servers
import urllib
f = urllib.urlopen("rss feed")
they deny my request saying your client dosent have permission...
i get reply but the reply contains " your client dosent have permission"
so how do i get around this and get the data...
http://vsbabu.org/mt/archives/2003/05/27/urllib2_setting_http_headers.html
If you want to use good old urllib
instead of newer, fancier urllib2
, then as urllib's docs say, and I quote,
For example, applications may want to specify a different User-Agent header than URLopener defines. This can be accomplished with the following code:
import urllib
class AppURLopener(urllib.FancyURLopener):
version = "App/1.7"
urllib._urlopener = AppURLopener()
Of course, you'll want a version
(aka User-Agent header) suitable for whatever version of Firefox (or w/ever else;-) you want to pretend you are;-).
精彩评论