博客
关于我
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/

你可能感兴趣的文章
mysql数据库命令备份还原
查看>>
mysql数据库基础教程
查看>>
MySQL数据库备份
查看>>
mysql数据库备份与恢复
查看>>
MySQL数据库备份实战
查看>>
Mysql数据库备份的问题:mysqldump: Got error: 1049: Unknown_无需整理
查看>>
mysql数据库如何重置密码是多少钱_MySQL数据库忘记root密码如何重置修改
查看>>
MySQL数据库安装配置与常用命令
查看>>
MySQL数据库实现主从同步数据
查看>>
mysql数据库导入导出_windows系统以及linux系统下的操作---linux工作笔记042
查看>>
mysql数据库导出导入
查看>>
MySQL数据库工具类之——DataTable批量加入MySQL数据库(Net版)
查看>>
mysql数据库常用命令
查看>>
MySQL数据库必会的增删查改操作(CRUD)
查看>>
MySQL数据库性能分析与调优实践
查看>>
mysql数据库扫盲,你真的知道什么是数据库嘛
查看>>
mysql数据库批量插入数据shell脚本实现
查看>>
MySQL数据库操作
查看>>
MySQL数据库故障排错
查看>>
MySQL数据库无法远程连接的解决办法
查看>>