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()

最新文章

  1. svn常用命令
  2. ubuntu eclipse 中安装 python + PyDev
  3. mysqldump 逻辑备份的正确姿势
  4. 如何更好地利用Pmd、Findbugs和CheckStyle分析结果
  5. DSP using MATLAB 示例 Example3.15
  6. 调试 rewrite
  7. log4j---------学习总结(一)
  8. php文件大小单位转换GB MB KB
  9. 【BZOJ】【2002】【HNOI2010】弹飞绵羊
  10. Tomcat启动后访问首页报错 显示JSP 空指针异常
  11. Apple LLVM 6.0 Warning: profile data may be out of date
  12. java io 流基础
  13. objectiv-c所有对象之间的交互是如何实现的?
  14. 线性代数(矩阵乘法):POJ 2778 DNA Sequence
  15. SQL Server sp_configure 控制内存使用
  16. CSS文本效果
  17. 洛谷P1856 [USACO5.5]矩形周长Picture
  18. tcp拥塞控制 tahoe reno new reno sack
  19. appium+java报错之nodejs报错
  20. STM32应用实例十一:基于SPI和AD7192的数据采集

热门文章

  1. xray写POC踩坑
  2. ASP.net发布项目引用了C++DLL后页面提示找不到指定模块的异常
  3. 虚拟机中Linux环境下使用Squid部署代理缓存服务(及透明传输)
  4. GraphHopper-初识
  5. nginx配置的记录
  6. Tomcat报错:No result type specified for result named 'success'
  7. pyrhon 第一个小购物车例子
  8. Docker 学习笔记(三):数据、网络、系统权限、docker-compose
  9. Bipartite Checking CodeForces - 813F (线段树按时间分治)
  10. Angular 学习笔记 (Angular 9 & ivy)