资源简介
用python爬取网络资源图片,学习的小例子。网络爬虫案例
代码片段和文件信息
#coding=utf-8
import requests
from bs4 import BeautifulSoup
import os
all_url = ‘http://www.mzitu.com‘
#http请求头
Hostreferer = {
‘User-Agent‘:‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)‘
‘Referer‘:‘http://www.mzitu.com‘
}
Picreferer = {
‘User-Agent‘:‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)‘
‘Referer‘:‘http://i.meizitu.net‘
}
#此请求头破解盗链
start_html = requests.get(all_urlheaders = Hostreferer)
#保存地址
path = ‘picture/‘
#找寻最大页数
soup = BeautifulSoup(start_html.text“html.parser“)
page = soup.find_all(‘a‘class_=‘page-numbers‘)
max_page = page[-2].text
same_url = ‘http://www.mzitu.com/page/‘
for n in range(1int(max_page)+1):
ul = same_url+str(n)
start_html = requests.get(ul headers = Hostreferer)
soup = BeautifulSoup(start_html.text“html.parser“)
all_a = soup.find(‘div‘class_=‘postlist‘).find_all(‘a‘target=‘_blank‘)
for a in all_a:
title = a.get_text() #提取文本
if(title != ‘‘):
print(“准备扒取:“+title)
#win不能创建带?的目录
if(os.path.exists(path+title.strip().replace(‘?‘‘‘))):
#print(‘目录已存在‘)
flag=1
else:
os.makedirs(path + title.s
- 上一篇:python+tensorflow的yolo实现代码
- 下一篇:分布交通流预测计算
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 一个多线程智能爬虫,爬取网站小说
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- 顶点小说单本书爬虫.py
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
评论
共有 条评论