import requests
import re
from urllib import parse
import os
from threading import Thread def download(i,j,key,url):
header = {'content-type': 'application/json',
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
"Connection":"keep-alive",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language":"zh-CN,zh;q=0.8"
}
response = requests.get(url,headers=header) link = re.findall(r'"objURL":"(.*?)"',response.text,re.S)
if not os.path.exists(key):
os.mkdir("./"+key+"/")
for web in link:
url = decodeurl(web)
print(url) try:
#allow_redirects=False 关闭重定向
pic = requests.get(url,timeout=10,headers=header,allow_redirects=False)
dirfile = "./"+key+"/" +key + '_' + str(j) + '.jpg'
fp = open(dirfile, 'wb')
fp.write(pic.content)
fp.close()
j += 1
except requests.exceptions.ConnectionError:
print(web,"【错误】当前图片无法下载")
continue
except requests.exceptions.ReadTimeout:
print(web, "【错误】超时")
continue
except requests.exceptions.ChunkedEncodingError:
print(web, "【错误】远程主机强迫关闭了一个现有的连接")
continue def decodeurl(url):
str_table = {
'_z2C$q': ':',
'_z&e3B': '.',
'AzdH3F': '/'
}
char_table = {
'w': 'a',
'k': 'b',
'v': 'c',
'': 'd',
'j': 'e',
'u': 'f',
'': 'g',
'i': 'h',
't': 'i',
'': 'j',
'h': 'k',
's': 'l',
'': 'm',
'g': 'n',
'': 'o',
'r': 'p',
'q': 'q',
'': 'r',
'f': 's',
'p': 't',
'': 'u',
'e': 'v',
'o': 'w',
'': '',
'd': '',
'n': '',
'': '',
'c': '',
'm': '',
'': '',
'b': '',
'l': '',
'a': ''
}
char_table = {ord(key): ord(value) for key, value in char_table.items()}
for key,value in str_table.items():
url = url.replace(key,value)
url = url.translate(char_table)
return url def main():
j = 0
key = "树叶标本"
data = parse.quote(str(key)) for i in range(j,2000,30):
if j == 0:
j +=1
url = "http://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord+=&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&word="+data+"&z=&ic=&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=1&fr=&step_word="+data+"&pn="+str(i)+"&rn=30&gsm=3c&1527055161957="
download(i,j,key,url)
j += 30 if __name__ == "__main__":
main()

python爬取百度图片的更多相关文章

  1. 百度图片爬虫-python版-如何爬取百度图片?

    上一篇我写了如何爬取百度网盘的爬虫,在这里还是重温一下,把链接附上: http://www.cnblogs.com/huangxie/p/5473273.html 这一篇我想写写如何爬取百度图片的爬虫 ...

  2. python 3 爬取百度图片

    python 3 爬取百度图片 学习了:https://blog.csdn.net/X_JS612/article/details/78149627

  3. Python 爬虫实例(1)—— 爬取百度图片

    爬取百度图片  在Python 2.7上运行 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Author: loveNight import jso ...

  4. python爬虫-爬取百度图片

    python爬虫-爬取百度图片(转) #!/usr/bin/python# coding=utf-8# 作者 :Y0010026# 创建时间 :2018/12/16 16:16# 文件 :spider ...

  5. selenium+chrome浏览器驱动-爬取百度图片

    百度图片网页中中,当页面滚动到底部,页面会加载新的内容. 我们通过selenium和谷歌浏览器驱动,执行js,是浏览器不断加载页面,通过抓取页面的图片路径来下载图片. from selenium im ...

  6. 使用python爬取百度贴吧内的图片

    1. 首先通过urllib获取网页的源码 # 定义一个getHtml()函数 def getHtml(url): try: page = urllib.urlopen(url) # urllib.ur ...

  7. Python爬取谷歌街景图片

    最近有个需求是要爬取街景图片,国内厂商百度高德和腾讯地图都没有开放接口,查询资料得知谷歌地图开放街景api 谷歌捷径申请key地址:https://developers.google.com/maps ...

  8. Python——爬取百度百科关键词1000个相关网页

    Python简单爬虫——爬取百度百科关键词1000个相关网页——标题和简介 网站爬虫由浅入深:慢慢来 分析: 链接的URL分析: 数据格式: 爬虫基本架构模型: 本爬虫架构: 源代码: # codin ...

  9. python 爬取百度url

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-08-29 18:38:23 # @Author : EnderZhou (z ...

随机推荐

  1. java 方法的重载重写

    面向对象有三大特性:封装,继承,多态 多态则需要满足三大条件1要有继承2要有重写3父类引用子类对象 很多人对方法的重载重写有很大疑问,下面我来介绍一下方法的重载重写 方法重载就是方法名称重复,加载参数 ...

  2. 浏览器端-W3School-HTML:HTML DOM Meta 对象

    ylbtech-浏览器端-W3School-HTML:HTML DOM Meta 对象 1.返回顶部 1. HTML DOM Meta 对象 Meta 对象 Meta 对象代表 HTML 的 一个 & ...

  3. Kotlin之定义变量

    java : int n = 30 ; final int m = 30 ; float k = 2.5f; string s = "sss"; short i = 5; bool ...

  4. nodejs之mongodb操作

    声明: 当查询到数据库数据后,对数据库数据进行遍历,可以采用toArray()函数,具体实现可以看第六点 1.本地安装mongodb 安装包:https://www.mongodb.com/downl ...

  5. Nova 启动虚拟机流程解析

    目录 文章目录 目录 前言 从请求说起 nova-api service 阶段 前言 Nova 启动虚拟机的东西太多,持续更新- 从请求说起 无论是通过 Dashboard 还是 CLI 启动一个虚拟 ...

  6. 63不同路径II

    题目: 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ).机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“Finish”).现在考 ...

  7. java:(json,ajax,path,Oracle的分页实例,Filter拦截器)

    1.json: <%@ page language="java" import="java.util.*" pageEncoding="UTF- ...

  8. Spring Boot 自定义注册 Servlet、Filter、Listener

    前言 在 Spring Boot 中已经移除了 web.xml 文件,如果需要注册添加 Servlet.Filter.Listener 为 Spring Bean,在 Spring Boot 中有两种 ...

  9. Leetcode基础篇30天30题系列之数组:模拟计算法

    作者:丁宋涛 数组:加一 题干: 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整 ...

  10. Logistic回归基础篇之梯度上升算法

    代码示例: import numpy as np import matplotlib.pyplot as plt def loadDataSet(): dataMat = [];labelMat = ...