[爬虫]爬虫时碰到的IOError: [Errno ftp error] [Errno 10060]错误的原因以及解决方法

IOError: [Errno ftp error] [Errno 10060]

原因是爬取页面过快造成暂时被网站ban掉的情况,设置time.sleep(1)就好,后来发现ban的时间不定,就自己动手写了个暴力的做法

import time


def 函数名(参数):
    error_time = 0
    while True:
        time.sleep(1)
        try:
            此处写执行的函数
        except:
            error_time += 1
            if error_time == 100:
                print 'your network is little bad'
                time.sleep(60)
            if error_time == 101:
                print 'your network is broken'
                break
            continue
        break

这样就能解决大多数被ban的情况,效果还可以。

猜你喜欢

转载自blog.csdn.net/xc_zhou/article/details/80603995
今日推荐