练手作业,找一些赏心悦目的图片跟大家一起交流,不过图片不是高清的,只是预览图,大哥们有好的方法弄高清的图吗
[Python] 纯文本查看 复制代码 import requests
from lxml import etree
import os
for i in range(1,40):
url='http://pic.netbian.com/4kmeinv/index_%d.html'
new_url=format(url%i)
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}
page=requests.get(url=new_url,headers=headers)
page.encoding=page.apparent_encoding
page_text=page.text
tree= etree.HTML(page_text)
li_list=tree.xpath('//div[@class="slist"]/ul/li')
if not os.path.exists('./picLibs'):
os.mkdir('./picLibs')
for li in li_list:
img_src='http://pic.netbian.com'+ li.xpath('./a/img/@src')[0]
img_name=li.xpath('./a/img/@alt')[0]+'.jpg'
img_data=requests.get(url=img_src,headers=headers).content
img_path='picLibs/'+img_name
with open (img_path,'wb')as fp:
fp.write(img_data)
print(img_name,"下载完成!") |