学习笔记:使用requests+Beautiful4爬取优美图库
BeautifulSoup需要掌握:
1.find()方法
2.find_all()方法
requests基本掌握.get就行。
代码如下:
import requests
from bs4 import BeautifulSoupurl = "https://www.umei.cc/meinvtupian/meinvxiezhen/"
resp = requests.get(url)
resp.encoding = "gbk", "gb232"
#print(resp.text)
soup = BeautifulSoup(resp.text, "html.parser")
fath_page = soup.find("div", class_="TypeList").find_all("a", class_="TypeBigPics")
n = 1
for a in fath_page:# print(a.get("href"))c_resp = requests.get(a.get("href"))c_resp.encoding="utf-8"#print(c_resp)c_soup=BeautifulSoup(c_resp.text,"html.parser")c_page = c_soup.find("div",class_="ImageBody").find("img").get("src")#c_url = c_page.get("href")new_url = requests.get(c_page).contentwith open(f"{n}.jpg" ,mode="wb") as f:f.write(new_url)print(f"下载了{n}张")n+=1
beta版本:(嘻嘻,有待改进。)
import requestsfrom bs4 import BeautifulSoupurl = "https://www.umei.cc/meinvtupian/meinvxiezhen/"
resp = requests.get(url)
resp.encoding = "gbk", "gb232"
#print(resp.text)
soup = BeautifulSoup(resp.text, "html.parser")
fath_page = soup.find("div", class_="TypeList").find_all("a", class_="TypeBigPics")for a in fath_page:for i in range(2, 20):#print(a.get("href"))str_url = str(a.get("href"))[0:-4]#print(str_url)stu=str_url+"_"+str(i)+".htm"print(stu)def get_stu(stu):try:c_resp=requests.get(stu)except AttributeError:c_resp.encoding="utf-8"print(c_resp)c_soup=BeautifulSoup(c_resp.text,"html.parser")c_page = c_soup.find("div",class_="ImageBody").find("img").get("src")#print(c_page)new_url = requests.get(c_page).contentreturn new_urlwith open(f"{n}.jpg" ,mode="wb") as f:f.write(new_url)print(f"下载了{n}张")n+=1
学习笔记:使用requests+Beautiful4爬取优美图库相关推荐
- 爬虫学习笔记-猫眼电影排行爬取
爬虫学习笔记-猫眼电影排行爬取 1 分析页面 https://maoyan.com/board/4 点击页码发现页面的URL变成: 初步推断出offset是一个偏移量的参数,当页面为第一页时offse ...
- python爬取优美图库
学了一段时间python,最近学习了一些python爬虫,今天写了一个爬取优美图库的的一段代码,下面给大家分享一下. 先看一下爬取的结果: 这段代码使用了下面的一些包,我们需要提前进行安装,在终端使用 ...
- python爬取优美图库海量图片,附加代码,一键爬取
优美高清图片为大家提供高清美女套图赏析,非高清不录入,大家的网速要给力. 今天教大家爬取优美图库网站中高质量的图片!! 简单易上手哦~ 使用工具: Python 3.6 pycharm 相关环境: r ...
- Python 爬取优美图库图片
# !/usr/bin/env python # -*-coding:utf-8-*- # date :2021/7/23 17:53 # author:Sabo"""爬 ...
- python第一天----爬取优美图库的图片
python第一天----爬取优美图库的图片 首先我们需要爬取的步骤: 1.选择爬取的网页,这里我选取的是https://www.umei.net/bizhitupian/,直接爬取的首页第一页的图片 ...
- Python使用bs4爬取优美图库
'''爬取优美图库 ''' import requests from bs4 import BeautifulSoup import time from tqdm import tqdm# 爬取页面源 ...
- 【爬虫学习2】Requests cookies爬取知乎个人timeline
上次用Requests爬取了静态网页-正则表达式加Requests爬取猫眼电影排行 这次想尝试使用requests.Session进行cookie登录爬取网页内容 -全部代码见于我的Git 准备素材 ...
- 爬虫学习笔记(用python爬取东方财富网实验)
参考文章以及视频:(11条消息) 爬虫实战 | 爬取东方财富网股票数据_简说Python的博客-CSDN博客.手把手教你从东方财富网上获取股票数据_哔哩哔哩_bilibili.[Python爬虫案例] ...
- 【Python3 爬虫学习笔记】用PySpider爬取虎嗅网并进行文章分析
–转自<1900-高级农民工>http://www.makcyun.top 安装并运行pyspider 安装pyspider pip3 install pyspider 运行pyspide ...
最新文章
- 基于数组的无锁队列(译)
- 微信翻译生日快乐的代码_微信「隐藏彩蛋」,你发现了没?
- python语言入门m-Python -m参数原理及使用方法解析
- CTF-练习平台-WEB之 签到题
- python 安装模块步骤
- 监控软件nagios错误总结
- GetHashCode() 的研究
- jQuery的Password Validation插件
- Centos7装NVIDIA显卡驱动(GPU)
- .Net如何统计在线人数
- 回味颜宁演讲:“勇敢做独一无二的你”
- Ubuntu安装指定版本clang-format
- 各个阶段的前端得会哪些“特殊”技能?
- 非常好用的终端命令,稀饭~
- LVS(三)LVS集群NAT模式
- 机械专业热门选题 论文+图纸+PPT
- c语言程序训练营,C语言编程强化训练营
- 一纸读懂另类数据 | 未央研究
- 课堂秩序难管理?这个方法造福师生
- 论职务犯罪案件侦查 z
热门文章
- Docker部署Django由浅入深系列(中): 双容器部署Django + Uwsgi + Nginx
- WordPress建站主机推荐
- mysql 按比例计算排名_计算MS SQL中的百分比排名
- 手机APP如何访问局域网服务器
- 汽车智造(一)| 移动机器人(AGV AMR)如何赋能汽车行业制造升级
- Linux-逻辑卷LVM
- 互联网舆情系统的架构实践
- php sku颜色,PHP 产品库 SPU、SKU 如何设计?
- mysql binlog events_使用SHOW binlog events查看binlog内容
- 认识Python继承:super()