首页 > python urllib2爬虫短时间访问同一个网站 被拒绝 求教

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

    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信息。 听说代理可以解决?


可以通过adsl和代理更换ip。


得看你的问题在哪

如果是因为短时间内访问频率过高导致服务器对该IP的限制
那显然是得用代理或者其它方法以改变访问的IP

【热门文章】
【热门文章】