1. 程式人生 > >[爬蟲]爬蟲時碰到的IOError: [Errno ftp error] [Errno 10060]錯誤的原因以及解決方法

[爬蟲]爬蟲時碰到的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的情況,效果還可以。