爬取一个图片网站时刚一下载几张图片就报错10054
代码如下
```
import time
import requests
from bs4 import BeautifulSoup
import re
n=1
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"}
resp=requests.get("
Error
https://m.enterdesk.com/special/sexygirl/%22,headers=headers
)
resp.encoding='utf-8'
html=resp.text
main_page = BeautifulSoup(resp.text,"html.parser")
alist = main_page.find_all("div",attrs={"class":"mbig_pic_tag"})
for a in alist:
href=a.find("a",attrs={"target":"blank"})['href']
child_page = requests.get(href)
child_page.encoding = 'utf-8'
child_page1 = BeautifulSoup(child_page.text, "html.parser")
src = child_page1.find("div", attrs={"class": "swiper-wrapper"}).find_all("img")
for pic_url in src:
finl_url=pic_url.get("src")
f = open("tu%s.jpg" % n, mode="wb")
f.write(requests.get(finl_url).content)
time.sleep(1)
print("下载了一张图片")
n += 1