PYTHON 爬虫 baidu美女图片
2024-08-27 05:27:34
from urllib import request
import re
import os
def main():
#page=request.urlopen("http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fr=&sf=1&fmq=1461834053046_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&itg=0&ie=utf-8&word=%E5%A4%B4%E5%83%8F#z=0&pn=&ic=0&st=-1&face=0&s=0&lm=-1" )
# "https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E4%B8%AD%E5%9B%BD&oq=%E4%B8%AD%E5%9B%BD&rsp=-1")
page = request.urlopen("https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E7%BE%8E%E5%A5%B3&oq=%E7%BE%8E%E5%A5%B3&rsp=-1")
context=page.read().decode('utf-8')
pic=re.findall("https://.*?jpg",context)
count = 0; # 文件的起始名称为 0
for url in pic:
print(url)
bytes = request.urlopen(url);
if (url.find('.') != -1): # 2
name =url[url.find('.', len(url) - 5):];
f = open("D:/image/" + str(count) + name, 'wb'); # 代开一个文件,准备以二进制写入文件
f.write(bytes.read()); # write并不是直接将数据写入文件,而是先写入内存中特定的缓冲区
f.flush(); # 将缓冲区的数据立即写入缓冲区,并清空缓冲区
f.close(); # 关闭文件
count += 1;
if __name__ == '__main__':
main()
最新文章
- svn常用命令
- ubuntu eclipse 中安装 python + PyDev
- mysqldump 逻辑备份的正确姿势
- 如何更好地利用Pmd、Findbugs和CheckStyle分析结果
- DSP using MATLAB 示例 Example3.15
- 调试 rewrite
- log4j---------学习总结(一)
- php文件大小单位转换GB MB KB
- 【BZOJ】【2002】【HNOI2010】弹飞绵羊
- Tomcat启动后访问首页报错 显示JSP 空指针异常
- Apple LLVM 6.0 Warning: profile data may be out of date
- java io 流基础
- objectiv-c所有对象之间的交互是如何实现的?
- 线性代数(矩阵乘法):POJ 2778 DNA Sequence
- SQL Server sp_configure 控制内存使用
- CSS文本效果
- 洛谷P1856 [USACO5.5]矩形周长Picture
- tcp拥塞控制 tahoe reno new reno sack
- appium+java报错之nodejs报错
- STM32应用实例十一:基于SPI和AD7192的数据采集
热门文章
- xray写POC踩坑
- ASP.net发布项目引用了C++DLL后页面提示找不到指定模块的异常
- 虚拟机中Linux环境下使用Squid部署代理缓存服务(及透明传输)
- GraphHopper-初识
- nginx配置的记录
- Tomcat报错:No result type specified for result named 'success'
- pyrhon 第一个小购物车例子
- Docker 学习笔记(三):数据、网络、系统权限、docker-compose
- Bipartite Checking CodeForces - 813F (线段树按时间分治)
- Angular 学习笔记 (Angular 9 &; ivy)