import requests
from lxml import etree
import os
def download(im_url,all_path):
requ=requests.get(im_url,headers=headers)
with open(all_path, 'wb') as f:
f.write(requ.content)
f.close()
def get_url(url,all_path):
requ=requests.get(url,headers=headers)
e=etree.HTML(requ.text)
im_urls=e.xpath('//img[@id="bigImg"]//@src')
for im_url in im_urls:
download(im_url,all_path)
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
}
if __name__=="__main__":
urls=['http://desk.zol.com.cn/bizhi/8668_1069{0}_2.html'.format(i) for i in range(11,19)]
names=['第{0}张'.format(i-10) for i in range(11,19)]
for url,name in zip(urls,names):
path=os.path.abspath('E:/picture')
im_name = name + '.jpg'
all_path = os.path.join(path, im_name)
get_url(url,all_path)
爬虫的简单实验,爬取照片
最新推荐文章于 2024-04-05 14:08:36 发布