python urllib2爬虫短时间访问同一个网站 被拒绝 求教,pythonurllib2, user_age


    user_agent="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"    headers = {'User-Agent': user_agent,'Host':"ggjd.cnstock.com",'DNT':'1'}resp=None        raw_content=""        try:            resp=urllib2.urlopen(req,timeout=10)        except urllib2.URLError as e:            if hasattr(e,'code'):                print "Error code : %s" %e.code            elif hasattr(e,'reason'):                print "Error reason : %s" %e.reason        finally:            if resp:                raw_content = resp.read()                time.sleep(1)                resp.close()

最后还是没有得到任何的error信息。 听说代理可以解决?

编橙之家文章,

评论关闭