博客
关于我
Python之爬虫-校花网
阅读量:445 次
发布时间:2019-03-06

本文共 727 字,大约阅读时间需要 2 分钟。

Python之爬虫-校花网

#!/usr/bin/env python# -*- coding:utf-8 -*-import reimport requests# 拿到校花网主页的内容response = requests.get('http://www.xiaohuar.com/')data = response.text# 拿到校花网所有的图片链接results = re.findall('lazysrc="(.*?)"', data)for result in results:  # type:str    # 判断是不是有链接的    if result.startswith('htt'):        pass    else:        img_result = 'http://www.xiaohuar.com/' + result        # 获取图片内容        img_response = requests.get(img_result)        img_data = img_response.content        img_name = result.split('/')[3]        img_filename = img_name + '.jpg'        print(img_filename)        # 保存图片内容        with open(img_filename, 'wb') as f:  # write,read,wb是写入二进制            f.write(img_data)            print('爬取成功一张')

转载地址:http://hzgyz.baihongyu.com/

你可能感兴趣的文章
Nginx 我们必须知道的那些事
查看>>
Nginx 源码完全注释(11)ngx_spinlock
查看>>
Nginx 的 proxy_pass 使用简介
查看>>
Nginx 的 SSL 模块安装
查看>>
Nginx 的优化思路,并解析网站防盗链
查看>>
Nginx 的配置文件中的 keepalive 介绍
查看>>
nginx 禁止以ip形式访问服务器
查看>>
Nginx 结合 consul 实现动态负载均衡
查看>>
Nginx 负载均衡与权重配置解析
查看>>
Nginx 负载均衡详解
查看>>
nginx 配置 单页面应用的解决方案
查看>>
nginx 配置https(一)—— 自签名证书
查看>>
nginx 配置~~~本身就是一个静态资源的服务器
查看>>
Nginx 配置服务器文件上传与下载
查看>>
Nginx 配置清单(一篇够用)
查看>>
Nginx 配置解析:从基础到高级应用指南
查看>>
Nginx 集成Zipkin服务链路追踪
查看>>
nginx 集群配置方式 静态文件处理
查看>>
nginx+php的搭建
查看>>
nginx+tomcat+memcached
查看>>