python3爬取全站美眉图片
爬取网站:https://www.169tp.com/xingganmeinv
该网站美眉图片有数百页,每页24张,共上万张图片,全部爬取下来
import urllib.request
import re
import os
from bs4 import BeautifulSoup page_flag = 0
base_url = "https://www.169tp.com/xingganmeinv/"
first_url ="https://www.169tp.com/xingganmeinv/list_1_1.html"
Imgnums = 0 def get_html(url):
response = urllib.request.urlopen(url)
html = response.read().decode('gb18030')
return html def get_Imgurl_list(html):
img_urllist = re.findall('src=["\']{1}(.+?\.jpg)["\']{1}', html)
return img_urllist def Download(img_urllist,page_flag,final_path,Imgnums):
num = 1
for imgurl in img_urllist:
imgname = "{}{}{}{}.jpg".format(final_path,page_flag,'_',num)
urllib.request.urlretrieve(imgurl,imgname)
print("已经爬取图片名:",imgname)
Imgnums += 1
num += 1 def makedir(path):
path = path.strip()
isExists = os.path.exists(path)
if not isExists:
print("创建了路径为 ",path," 的文件夹")
os.makedirs(path)
return True
else:
print("路径为 ",path," 的文件夹已经存在")
return False filepath = input("请输入保持图片的文件夹路径:")
print(filepath)
name = input("请输入保存图片的文件夹名:")
print(name)
finalpath = filepath + name
makedir(finalpath)
finalpath += '\\'
print(f"图片保存路径: {finalpath}") Download(get_Imgurl_list(first_url),page_flag,finalpath,Imgnums)
mysoup = BeautifulSoup(get_html(first_url),'html.parser')
next_page = mysoup.find('div',attrs = {'class':'page'}).find('li',text = '下一页').find('a')
while next_page:
new_url = base_url + next_page['href']
page_flag += 1
Download(get_Imgurl_list(get_html(new_url)),page_flag,finalpath,Imgnums)
mysoup = BeautifulSoup(get_html(new_url),'html.parser')
next_page = mysoup.find('div',attrs = {'class':'page'}).find('li',text = '下一页').find('a')
print(f"下载完成,共下载了 {Imgnums} 张图片!")
运行截图:

图片名命名规则:存储路径+页码+下划线+图片号+.jpg
图片文件夹截图:

python3爬取全站美眉图片的更多相关文章
- Python爬取全站妹子图片,差点硬盘走火了!
在这严寒的冬日,为了点燃我们的热情,今天小编可是给大家带来了偷偷收藏了很久的好东西.大家要注意点哈,我第一次使用的时候,大意导致差点坏了大事哈! 1.所需库安装 2.网站分析 首先打开妹子图的官网(m ...
- Python3爬取美女妹子图片转载
# -*- coding: utf-8 -*- """ Created on Sun Dec 30 15:38:25 2018 @author: 球球 "&qu ...
- python3爬取动态网站图片
思路: 1.图片放在<image>XXX</image>标签中 2.利用fiddler抓包获取存放图片信息的js文件url 3.利用requests库获取html内容,然后获取 ...
- python3爬取1024图片
这两年python特别火,火到博客园现在也是隔三差五的出现一些python的文章.各种开源软件.各种爬虫算法纷纷开路,作为互联网行业的IT狗自然看的我也是心痒痒,于是趁着这个雾霾横行的周末瞅了两眼,作 ...
- python3爬取女神图片,破解盗链问题
title: python3爬取女神图片,破解盗链问题 date: 2018-04-22 08:26:00 tags: [python3,美女,图片抓取,爬虫, 盗链] comments: true ...
- 如何用python爬虫从爬取一章小说到爬取全站小说
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取http ...
- python 爬虫入门----案例爬取上海租房图片
前言 对于一个net开发这爬虫真真的以前没有写过.这段时间学习python爬虫,今天周末无聊写了一段代码爬取上海租房图片,其实很简短就是利用爬虫的第三方库Requests与BeautifulSoup. ...
- Python3 爬取微信好友基本信息,并进行数据清洗
Python3 爬取微信好友基本信息,并进行数据清洗 1,登录获取好友基础信息: 好友的获取方法为get_friends,将会返回完整的好友列表. 其中每个好友为一个字典 列表的第一项为本人的账号信息 ...
- 使用Python爬虫爬取网络美女图片
代码地址如下:http://www.demodashi.com/demo/13500.html 准备工作 安装python3.6 略 安装requests库(用于请求静态页面) pip install ...
随机推荐
- .NET开源工作流RoadFlow-流程运行-运行时监控
流程实例参与者都可以随时查看流程实例的运行情况,如果是待办任务,则在待办事项列表的后面点查看,如果是已完成任务则可以在已办事项列表的后面点查看: 打开之后默认为列表方式显示流程的处理过程,还可以点图形 ...
- atoi、itoa,strcpy,strcmp,memcpy等实现
原文:http://www.cnblogs.com/lpshou/archive/2012/06/05/2536799.html 1.memcpy.memmove.memset源码 link:http ...
- JNLP文件具体说明编辑
JNLP(Java Network Launching Protocol )是java提供的一种可以通过浏览器直接执行java应用程序的途径,它使你可以直接通过一个网页上的url连接打开一个java应 ...
- 安装busybox玩玩
到http://www.busybox.net/downloads/binaries/下载放到sdcard然后adb shellsumount -o remount,rw -t yaffs2 /dev ...
- jquery attr和prop区别
<input type="checkbox" /> <script> $(function() { $('input').click(function() ...
- SQL计算上下两行某列的差
SELECT * FROM #TempHuDong SELECT * FROM #TempHuDong SELECT TOP 1 ABS(a.num -b.num) '差' FROM (select ...
- Web API 2 入门——创建ASP.NET Web API的帮助页面(谷歌翻译)
在这篇文章中 创建API帮助页面 将帮助页面添加到现有项目 添加API文档 在敞篷下 下一步 作者:Mike Wasson 创建Web API时,创建帮助页面通常很有用,以便其他开发人员知道如何调用A ...
- 通过CXF,开发rest协议接口
1. 引入cxf的jar包 pom文件里面直接增加依赖 < dependency> <groupId > junit</ groupId> <artifact ...
- nohup命令、setsid命令、Daemon(守护进程)简要梳理
nohup命令 当用户注销(logout)或者网络断开时,终端会收到 HUP(hangup)信号从而关闭其所有子进程.因此,我们的解决办法就有两种途径:要么让进程忽略 HUP 信号,要么让进程运行在新 ...
- 巧用padding生成正方形DIV
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...