0

我想创建一个 urllib2 开启器,所以它看起来就像是一部手机。我不知道我应该改变什么,或者你可能知道任何现有的图书馆可以做到这一点。

这就是我现在所拥有的:

cj=cookielib.CookieJar()
#Process Hadlers
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
#install opener, now all the calls to urllib2.urlopen use this opener
urllib2.install_opener(opener)
opener.addheaders=[
                    ('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'),
                    #('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
                    ('Accept-Language', 'en-gb,en;q=0.5'),
                    ('Accept-Encoding', 'gzip,deflate'),
                    ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
                    ('Keep-Alive', '115'),
                    ('Connection', 'keep-alive'),
                    ('Cache-Control', 'max-age=0'),
                    ('Referer', 'http://yahoo.com'),
                ]

但我希望网站认为我的 urllib2 开启器是一部手机(不管是哪一部)

谢谢你。

4

1 回答 1

1

网站User-Agent通常使用 HTTP 标头来识别您的设备。从以下位置选择一个与您的预期设备匹配的设备:http ://www.useragentstring.com/pages/useragentstring.php

于 2012-10-12T23:00:20.247 回答