我使用了代理,下面是守则。
20 req = urllib2.Request(url)
21 # run the request for each proxy
22 # now set the proxy
23 req.set_proxy(proxy, "http")
24 req.add_header( User-Agent , Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 )
25 req.add_header( Referer , http://www.google.com/ )
26 # time it
27 start = time.time()
28 # try to open the URL
29
30 time.sleep(maxwait*random.random())
31 #response = urllib2.urlopen(req)
32 opener = urllib2.build_opener()
33 response = opener.open(req).read()
一台机器(直面和直线)的工程罚款,但在另一台机器(不同的IP)的终端机上运行时失败,有以下错误。
urllib2.HTTPError: HTTP Error 403: Forbidden
任何线索? 感谢gu!