Python 爬虫:煎蛋网妹子图

使用 Headless Chrome 替代了 PhatomJS。

图片保存到指定文件夹中。

 1 import requests
 2 from bs4 import BeautifulSoup
 3 from selenium import webdriver
 4 from selenium.webdriver.chrome.options import Options
 5 
 6 chrome_options = Options()
 7 chrome_options.add_argument('--headless')
 8 chrome_options.add_argument('--disable-gpu')
 9 driver = webdriver.Chrome(chrome_options=chrome_options)
10 dir = 'C:/spider-download/jandan-girls/'
11 img_urls = []
12 page_urls = ["http://jandan.net/ooxx/page-{}#comments".format(str(i)) for i in range(5, 6)]
13 
14 def GetImgUrl(u):
15     driver.get(u)
16     html = driver.page_source
17     soup = BeautifulSoup(html, 'lxml')
18     images = soup.select('a.view_img_link')
19     for i in images:
20         t = i.get('href')
21         if str('gif') in str(t):
22             pass
23         else:
24             img_url = 'http:' + t
25             img_urls.append(img_url)
26 
27 def DownloadImg():
28     n = 1
29     for i in img_urls:
30         print('' + str(n) + ' 张 ... ', end='')
31         with open(dir + i[-20:], 'wb') as f:
32             f.write(requests.get(i).content)
33         print('OK!')
34         n = n + 1
35 
36 for u in page_urls:
37     GetImgUrl(u)
38 print('*** 开始下载 ***')
39 DownloadImg()
40 print('*** 下载完成 ***')

 

转载于:https://www.cnblogs.com/deepcho/p/jandan-girls-spider.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值