我稍稍改了改,可以的,另外字典data的i不要带引号。import requests
import os
from lxml import etree
# 创建一个文件夹,保存所有图片
if not os.path.exists('post'):
os.mkdir('post')
url = 'http://www.jkl.com.cn/cn/phoLis.aspx?id=697'
for i in range(1, 5):
data = {'__EVENTARGUMENT': i}
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'}
r = requests.get(url=url, params=data, headers=headers)
html = etree.HTML(r.text)
result = html.xpath('//div[@class="proLis"]//img/@src')
print(result)
|