首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python爬虫之煎蛋网图片下载

Python爬虫之煎蛋网图片下载

作者头像
罗罗攀
发布2019-02-22 10:12:14
5900
发布2019-02-22 10:12:14
举报

受程序员群的影响(自己污的本性),他们总是带我开车,想想我也该收集一些资料了(美女图片)

代码

import requests
from lxml import etree

urls = ['http://jandan.net/ooxx/page-{}'.format(str(i)) for i in range(0,20)]
path = 'C://Users/Administrator/Desktop/煎蛋网/'

header = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
}

def get_photo(url):
    html = requests.get(url)
    selector = etree.HTML(html.text)
    photo_urls = selector.xpath('//p/a[@class="view_img_link"]/@href')
    for photo_url in photo_urls:
        data = requests.get('http:'+photo_url,headers=header)
        fp = open(path + photo_url[-10:],'wb')
        fp.write(data.content)
        fp.close()

for url in urls:
    get_photo(url)

我以前做个视频,这次用不了,出错,爬虫只有进行时啊!!!!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.02.08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档