import urllib.request from lxml import etree def create_request(page): if(page==1): url='https://sc.chinaz.com/tupian/fengjing.html' else: url='https://sc.chinaz.com/tupian/fengjing.html_'+str(page)+'.html' headers={ 'user-agent': '自己的ua' } request=urllib.request.Request(url=url,headers=headers) return request def get_response(request): response=urllib.request.urlopen(request) content=response.read().decode('utf-8') return content def download(content): tree=etree.HTML(content) src_list=tree.xpath('//div/img/@data-original') name_list=tree.xpath('//div/img/@alt') for i in range(len(src_list)): url='https:'+src_list[i] name=name_list[i] print(url) print(name) urllib.request.urlretrieve(url=url,filename=name+'.png')
标签:24,name,url,list,request,urllib,content,素材,2022 From: https://www.cnblogs.com/yhkdw/p/17274694.html