首页 > python io操作等待问题

python io操作等待问题

def get_html(url):
    request_head={}
    request_head['User-Agent']='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
    req=urllib.request.Request(url,headers=request_head)
    image=urllib.request.urlopen(req)
    html=image.read()
    return html
    
def save_img(url,file_address):
    html=get_html(url)
    baidu=open(file_address,'wb')
    baidu.write(html)
    baidu.close()
    

实际操作中当处理一个上百条的列表图片保存时,会出现某个图片保存操作卡住,无限等待的情况,
而且多次执行同一操作,卡住的地方都不相同,刚接触爬虫,不知道是什么原因?


阻塞的socket,试着用下gevent,打个socket的猴子补丁

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