win1990
发表于 2019-12-22 20:26:32
{:5_95:}
win1990
发表于 2019-12-22 20:48:50
import requests,time,parsel
headers={
'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Referer': 'https://www.mzitu.com/mm/'
}
def Download_tu(tu_download,tu_name):#下载一张图片
tu_pian=requests.get(tu_download,headers=headers)
s='E:\\下载库\\图片\\图片-1'#设置储存路径,这个win系统加上\\ 或者自己创建路径。
with open(s+'\\'+tu_name+'.jpg','wb') as f:
f.write(tu_pian.content)#写入图片
def Download_tuji(url,n):#下载一个图集
response=requests.get(url,headers=headers)#发送网络请求
nei_rong=parsel.Selector(response.text)#解析网页
ye_shu=int(nei_rong.xpath('//div/a/span/text()').get())#获取图片最大页数
for i in range(ye_shu):
time.sleep(0.3)#设置下载延时
tu_download=nei_rong.xpath('//p/a/img/@src').get()#获取图片下载地址
huan_ye=nei_rong.xpath('//p/a/@href').get()#获取换页地址
tu_name=nei_rong.xpath('//div/h2/text()').get()#提取图片名字
print(f'正在下载第{i+1}张:{tu_name},此系列共有张{ye_shu}图片,总共下载了{n}张')
#print(tu_download,huan_ye,tu_name)
Download_tu(tu_download,tu_name)
url=huan_ye#换一页
response=requests.get(url,headers=headers)#换请求新页面
nei_rong=parsel.Selector(response.text)
n+=1#计数
return n
def Download_yiye(url):#下载整页图
response=requests.get(url,headers=headers)
nei_rong=parsel.Selector(response.text)
urls=nei_rong.xpath('//*[@id="pins"]/li/a/@href').getall()
n=1#获取当前页面不同类型图集的链接
for url in urls:
print(url)#打印要下载的图集地址
n=Download_tuji(url,n)#下载图片
url='https://www.mzitu.com/japan//'#要爬取的网址
Download_yiye(url)
葵花菜籽油
发表于 2019-12-22 21:19:20
厉害呀
ZCJKDG
发表于 2019-12-22 21:21:19
11111
菜菜菜菜
发表于 2019-12-22 21:36:48
666666666666
随便找找看看
发表于 2019-12-22 21:42:14
我是来学习的。好好学习,天天向上
cocoone
发表于 2019-12-22 22:29:33
我是来看代码的
BlaBlaL
发表于 2019-12-22 22:43:40
厉害
NTR
发表于 2019-12-22 22:49:49
import requests
from lxml import etree
i = 0
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3088.3 Safari/537.36","Referer":"http://www.mzitu.com/all/"}
url = 'https://www.mzitu.com/tag/meitun/page/2/' # 此处网址根据需要修改
data = requests.get(url,headers=headers).text
s = etree.HTML(data)
file = s.xpath('//*[@id="pins"]/li')
for div in file:
url_te = div.xpath('./a/@href')
data_te = requests.get(url_te,headers=headers).text
s_te = etree.HTML(data_te)
page = int(s_te.xpath('/html/body/div/div/div/a/span/text()'))
# 图片列表页
for x in range(1,page):
urls = url_te + '/' + str(x)
data_s = requests.get(urls,headers=headers).text
s_s = etree.HTML(data_s)
img_url = s_s.xpath('/html/body/div/div/div/p/a/img/@src')
r = requests.get(img_url,headers=headers)
# 保存图片
path= str('F:\\py_exe\\catchImg\\img' + str(i) + '.png') # 此处路径需要修改
with open(path,'wb') as f:
f.write(r.content)
i+=1
秃头也不进工厂
发表于 2019-12-22 23:48:50
3
Lucases
发表于 2019-12-23 00:01:59
学习
wwwrkf
发表于 2019-12-23 08:42:58
看看
遇叶
发表于 2019-12-23 08:54:05
厉害
15116779901
发表于 2019-12-23 12:36:56
1
gudujian158411
发表于 2019-12-23 14:30:04
学习一下
pathon小白
发表于 2019-12-23 14:34:31
学习一下
findland
发表于 2019-12-23 14:50:07
为了网址
13576650969
发表于 2019-12-23 14:59:51
{:10_254:}
tiw143
发表于 2019-12-23 16:27:41
{:5_109:}大佬厉害
anlianwei
发表于 2019-12-23 16:32:41
学习学习