当前位置:网站首页>Python爬蟲實戰詳解:爬取圖片之家
Python爬蟲實戰詳解:爬取圖片之家
2020-11-06 01:17:00 【itread01】
前言
本文的文字及圖片來源於網路,僅供學習、交流使用,不具有任何商業用途,版權歸原作者所有,如有問題請及時聯絡我們以作處理
如何使用python去實現一個爬蟲?
- 模擬瀏覽器
請求並獲取網站資料
在原始資料中提取我們想要的資料 資料篩選
將篩選完成的資料做儲存
完成一個爬蟲需要哪些工具
- Python3.6
- pycharm 專業版
目標網站
圖片之家
https://www.tupianzj.com/
爬蟲程式碼
匯入工具
python 自帶的標準庫
import ssl
系統庫 自動建立儲存資料夾
import os
下載包
import urllib.request
網路庫 第三方包
import requests
網頁選擇器
from bs4 import BeautifulSoup
預設請求https網站不需要證書認證
ssl._create_default_https_context = ssl._create_unverified_context
模擬瀏覽器
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', }
自動建立資料夾
if not os.path.exists('./插畫素材/'): os.mkdir('./插畫素材/') else: pass
請求操作
url = 'https://www.tupianzj.com/meinv/mm/meizitu/' html = requests.get(url, headers=headers).text
對頁面原始資料做資料提取
soup = BeautifulSoup(html, 'lxml') images_data = soup.find('ul', class_='d1 ico3').find_all_next('li') for image in images_data: image_url = image.find_all('img') for _ in image_url: print(_['src'], _['alt'])
下載
try: urllib.request.urlretrieve(_['src'], './插畫素材/' + _['alt'] + '.jpg') except: pass
效果圖
版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://www.itread01.com/content/1604499424.html
边栏推荐
- 用Keras LSTM构建编码器-解码器模型
- Dapr實現分散式有狀態服務的細節
- Basic principle and application of iptables
- 6.9.2 session flashmapmanager redirection management
- In depth understanding of the construction of Intelligent Recommendation System
- 網路程式設計NIO:BIO和NIO
- Probabilistic linear regression with uncertain weights
- Network programming NiO: Bio and NiO
- [译] 5个Vuex插件,给你的下个VueJS项目
- 对pandas 数据进行数据打乱并选取训练机与测试机集
猜你喜欢
自然语言处理-搜索中常用的bm25
hadoop 命令总结
python jieba分词(结巴分词)、提取词,加载词,修改词频,定义词库
网络安全工程师演示:原来***是这样获取你的计算机管理员权限的!【维持】
mongodb(从0到1),11天mongodb初级到中级进阶秘籍
自然语言处理之命名实体识别-tanfordcorenlp-NER(一)
JVM内存区域与垃圾回收
Elasticsearch database | elasticsearch-7.5.0 application construction
Didi elasticsearch cluster cross version upgrade and platform reconfiguration
文本去重的技术方案讨论(一)
随机推荐
keras model.compile损失函数与优化器
如何在Windows Server 2012及更高版本中將域控制器降級
【Flutter 實戰】pubspec.yaml 配置檔案詳解
恕我直言,我也是才知道ElasticSearch条件更新是这么玩的
通过深层神经网络生成音乐
【QT】 QThread部分原始碼淺析
python 保存list数据
Jmeter——ForEach Controller&Loop Controller
GBDT与xgb区别,以及梯度下降法和牛顿法的数学推导
高级 Vue 组件模式 (3)
10 easy to use automated testing tools
二叉树的常见算法总结
5.5 ControllerAdvice注解 -《SSM深入解析与项目实战》
如何将分布式锁封装的更优雅
如何成为数据科学家? - kdnuggets
企业数据库的选择通常由系统架构师主导决策 - thenewstack
什么是无副作用的函数方法?如何取名? - Mario
[译] 5个Vuex插件,给你的下个VueJS项目
C language 100 question set 004 - statistics of the number of people of all ages
Flink on paasta: yelp's new stream processing platform running on kubernetes