import requests from lxml import etree if __name__ == '__main__': #被爬取的url地址 url = 'http://jianlimb.cn/biaogejianlimoban/' headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0' } page_text = requests.get(url=url,headers=headers).text #实例化类对象 tree = etree.HTML(page_text) li_list = tree.xpath('//div[@class="pic-item-list oh"]//li') #获取读取到的li列表,重列表中拼接url地址,并保存文件到本地 for li in li_list: img_url = li.xpath('./a/@href')[0] img_title = li.xpath('./a/div[@class="pic-item-image pr"]/span/img/@alt')[0] img_down = li.xpath('./a/div[@class="pic-item-image pr"]/span/img/@data-original')[0] # print(img_url,img_title) data = requests.get(url=img_url,headers=