当前位置: 移动技术网 > IT编程>脚本编程>Python > python-python爬取妹子图片

python-python爬取妹子图片

2019年01月23日  | 移动技术网IT编程  | 我要评论

蒙嘉丽,袁宝璟和苗圩,重庆时报电子版

 1 # -*-  conding=utf-8 -*-
 2 
 3 import  requests
 4 from  bs4 import  beautifulsoup
 5 import io
 6 
 7 url = "https://www.mzitu.com/164871"
 8 #referer = ? 是模拟电脑操作
 9 headers = {"referer":"https://www.mzitu.com/164871","user-agent":"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/55.0.2883.87 safari/537.36"}
10 html = requests.get(url)
11 soup = beautifulsoup(html.content,'lxml')
12 text = soup.find_all("span")[10].text
13 print(text)
14 title = soup.find("h2",class_='main-title').text
15 #获取图片的地址
16 for i in range(1,10):
17    #herf 为访问的地址
18    herf = url +'/'+ str(i)
19    #在次解析新的url(这个url就是妹子的连接)
20    html = requests.get(herf,headers=headers)
21    beautiful = beautifulsoup(html.text,'lxml')
22    #获取妹子的图片连接
23    pic_url = beautiful.find('img',alt=title)
24    print(pic_url)
25    html = requests.get(pic_url['src'],headers=headers)
26    # print(html.content)
27    # file_name = pic_url['src'].split(r'/')[-1]
28    "
29    # print(file_name)
30 
31    f = open(str(i)+'.jpg','wb')  # 名称
32    f.write(html.content)  #写入图片
33    f.close()
view code

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网