python爬虫-爬取你想要的小姐姐
一、准备
1. 原地址

2. 检查html发现,网页是有规则的分页, 最大图片的class为pic-large
二、代码
import requests
import os
from bs4 import BeautifulSoup url = 'http://www.win4000.com/wallpaper_detail_157712.html'
imgmkdir = 'D://Download//ghost_1//' # 获取网页url
def getUrlList():
imgUrlList = []
for i in range(0, 10):
imgUrl = ''
url_split = url.split('.html')
if not i == 0:
imgUrl += url_split[0] + '_' + str(i) + '.html'
# print(imgUrl)
imgUrlList.append(imgUrl) return imgUrlList # 下载图片
def downImg(imgUrl):
try:
if not os.path.exists(imgmkdir):
os.mkdir(imgmkdir)
if not os.path.exists(imgUrl):
r = requests.get(imgUrl)
r.raise_for_status()
# 使用with语句可以不用自己手动关闭已经打开的文件流
imgpath = imgmkdir + imgUrl.split('/')[-1]
# 开始写文件, wb表示写二进制文件
with open(imgpath, 'wb') as f:
f.write(r.content)
print(imgUrl + '【爬取完成】')
else:
print(imgUrl.split('/')[-1] + '【文件已存在】')
except Exception as e:
print("爬取失败" + str(e)) # 获取imgHtml标签
def getcontent(soup):
for i in soup.find_all('img', class_='pic-large'):
imgsrc = i['src']
if imgsrc.find('http') >= 0 or imgsrc.find('https') >= 0:
# 下载图片
downImg(imgsrc) # 根据url获取html源码
def getHtmlByUrl(htmlUrl):
htmlText = requests.get(htmlUrl).content
# 使用beautifulSoup解析html
soup = BeautifulSoup(htmlText, 'lxml') return soup def main():
htmlUrlList = getUrlList()
for url in htmlUrlList:
htmltext = getHtmlByUrl(url)
getcontent(htmltext) if __name__ == '__main__':
main()
三、结果

四、总结
代码用比较笨的方法来获取,先试水
python爬虫-爬取你想要的小姐姐的更多相关文章
- 使用Python爬虫爬取网络美女图片
代码地址如下:http://www.demodashi.com/demo/13500.html 准备工作 安装python3.6 略 安装requests库(用于请求静态页面) pip install ...
- Python爬虫爬取全书网小说,程序源码+程序详细分析
Python爬虫爬取全书网小说教程 第一步:打开谷歌浏览器,搜索全书网,然后再点击你想下载的小说,进入图一页面后点击F12选择Network,如果没有内容按F5刷新一下 点击Network之后出现如下 ...
- python爬虫—爬取英文名以及正则表达式的介绍
python爬虫—爬取英文名以及正则表达式的介绍 爬取英文名: 一. 爬虫模块详细设计 (1)整体思路 对于本次爬取英文名数据的爬虫实现,我的思路是先将A-Z所有英文名的连接爬取出来,保存在一个cs ...
- 一个简单的python爬虫,爬取知乎
一个简单的python爬虫,爬取知乎 主要实现 爬取一个收藏夹 里 所有问题答案下的 图片 文字信息暂未收录,可自行实现,比图片更简单 具体代码里有详细注释,请自行阅读 项目源码: # -*- cod ...
- Python爬虫 - 爬取百度html代码前200行
Python爬虫 - 爬取百度html代码前200行 - 改进版, 增加了对字符串的.strip()处理 源代码如下: # 改进版, 增加了 .strip()方法的使用 # coding=utf-8 ...
- 用Python爬虫爬取广州大学教务系统的成绩(内网访问)
用Python爬虫爬取广州大学教务系统的成绩(内网访问) 在进行爬取前,首先要了解: 1.什么是CSS选择器? 每一条css样式定义由两部分组成,形式如下: [code] 选择器{样式} [/code ...
- Python爬虫|爬取喜马拉雅音频
"GOOD Python爬虫|爬取喜马拉雅音频 喜马拉雅是知名的专业的音频分享平台,用户规模突破4.8亿,汇集了有声小说,有声读物,儿童睡前故事,相声小品等数亿条音频,成为国内发展最快.规模 ...
- python爬虫爬取内容中,-xa0,-u3000的含义
python爬虫爬取内容中,-xa0,-u3000的含义 - CSDN博客 https://blog.csdn.net/aiwuzhi12/article/details/54866310
- python爬虫-爬取百度图片
python爬虫-爬取百度图片(转) #!/usr/bin/python# coding=utf-8# 作者 :Y0010026# 创建时间 :2018/12/16 16:16# 文件 :spider ...
随机推荐
- 模板 - 字符串/数据结构 - 字典树/Trie
使用静态数组的nxt指针的设计,大概比使用map作为nxt指针的设计要快1倍,但空间花费大概也大1倍.在数据量小的情况下,时间和空间效率都不及map<vector,int>.map< ...
- jackson实现json转换
第一步.导包.导入jar包或者在maven项目中导入坐标(jackson-annotations:jackson-core:jackson-databind) 第二步.通过无参构造创建核心类Objec ...
- spring线程池的应用
加载xml文件 在ApplicationContext.xml文件里面添加 xmlns:task="http://www.springframework.org/schema/task&qu ...
- gcov—a Test Coverage Program
gcov—a Test Coverage Program https://coverage.readthedocs.io/en/v4.5.x/cmd.html 覆盖率测试
- Mac OS -bash: psql: command not found 使用 psql 命令报错
使用 psql 在 mac os 系统上登录,系统显示没有 psql 这个命令存在 解决方法如下: 将 postgresql 的 bin 目录添加到环境变量中即可 export PATH=" ...
- Spring cloud微服务安全实战-5-8实现基于session的SSO(认证服务器的session有效期)
认证服务器 session的有效期. 也就是认证服务器上的session的有效期 生成环境下,认证服务器一定是一个集群.集群.那么session一定是要在所有的服务器之间进行共享的.最简单的方式是用S ...
- bat函数调用 带返回值
bat 脚本之 使用函数 摘自:https://blog.csdn.net/peng_cao/article/details/73999076 综述 bat函数写法 bat函数调用 bat函数返回值 ...
- 【swoole】PHP+Swoole+Linux实现进程监控
脚本代码 class Server { const PORT = 8888; public function port() { //netstat -anp 2>/dev/null| grep ...
- 123457123456#2#----com.MC.ShiZi365--前拼后广--儿童识字Game-mc22222222222222222
com.MC.ShiZi365--前拼后广--儿童识字Game-mc
- build doris 0.11.5 on centos 7/ubuntu
doris has envolved many thirdparty components since v0.9. so the build progress has changed a lot si ...