pre 如何解决 find 表达 乱码 如何 python findall
- dir_name_list = re.findall(r' < span id = "thread_subject" > ([A - Za - z0 - 9\x80 - \xfff\. ()\s\ [\]\ - \ + ] + ) < /span>',str)/
使用其中的 \ x80-\xfff,网上有些教程写为 \ x80-\xff,实际使用中发现只能匹配双字节的中文,个人更改为三字节。
- dir_name.decode('gb2312').encode('utf - 8')
- # urllib.urlretrieve(each_pic,pic_name)
- request = requests.get(each_pic,timeout=10,stream=True)
- with open(pic_name, 'wb') as fh:
- # Walk through the request response in chunks of 1024 * 1024 bytes, so 1MiB
- for chunk in request.iter_content(10240 * 10240):
- # Write the chunk to the file
- fh.write(chunk)
网上有说在 socket 中设置 timeout,这样是不行的,timeout 后程序停止。
爬虫问题汇总 + 解决
来源: http://www.bubuko.com/infodetail-2270065.html