import requests
import re
from pyquery import PyQuery as pq
headers = {
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
def qcmn(page):
url = 'http://www.cgtpw.com/qcmn/index_{}.html'.format(page)
response = requests.get(url).content.decode('utf-8')
# print(response)
ex = '[a-zA-z]+://[^\s]*.jpg'
result = re.findall(ex, response,re.S)
for src in result:
img_data = requests.get(url=src,headers=headers).content
image_name = src.split('/')[-1]
file_url= r"E:\pythonProject1\文件操作\img_dir"+image_name
with open(file_url,mode='wb') as fb:
fb.write(img_data)
print("爬取成功")
# for i in range (1,10):
# f_obj.write("")
re.findall()
for page in range(4,6):
qcmn(page)
12-23
1492