python根据关键字以及id值爬取图虫网上高质量大图
import requests
import re import os
import time
print("ready....")
def downPic(dirs, keyword, imgId):
headers_downPic = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Host': 'p9.pstatp.com',
'Pragma': 'no-cache',
'Upgrade-Insecure-Requests': '',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
}
url = 'https://p9.pstatp.com/weili/l/{}.webp'.format(imgId)
print("line20: "+url)
while True:
try:
res = requests.get(url, headers=headers_downPic)
break
except:
time.sleep(30) savefile = os.path.join(dirs, keyword, imgId + ".jpg")
if not os.path.exists(os.path.dirname(savefile)):
os.makedirs(os.path.dirname(savefile))
with open(savefile, 'wb') as f:
f.write(res.content)
print(url, "下载成功! time ", time.ctime()) def visitContent(keyword, savePath):
for page in range(2, 51):
headers_visitContent = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'no-cache',
'cookie': 'PHPSESSID=eb7kn10j6ed22srj8a9gg8upl3; webp_enabled=1; _ga=GA1.2.1531772161.1540775429; _gid=GA1.2.1509491512.1540775429; weilisessionid=c39a62f3e6996be04e27e693afd32488; wluuid=WLGEUST-0629E5A8-FD7F-BF5F-7C03-5621C88DAA08; wlsource=tc_pc_home_search; webp_enabled=0; _ga=GA1.3.1531772161.1540775429; _gid=GA1.3.1509491512.1540775429; qimo_seosource_e7dfc0b0-b3b6-11e7-b58e-df773034efe4=%E7%AB%99%E5%86%85; qimo_seokeywords_e7dfc0b0-b3b6-11e7-b58e-df773034efe4=; href=https%3A%2F%2Fstock.tuchong.com%2Fsearch%3Fsource%3Dtc_pc_home_search%26term%3D%25E7%25BE%258E%25E5%25B0%2591%25E5%25A5%25B3; accessId=e7dfc0b0-b3b6-11e7-b58e-df773034efe4; bad_ide7dfc0b0-b3b6-11e7-b58e-df773034efe4=cb76ee61-db17-11e8-bb24-e322d5547169; nice_ide7dfc0b0-b3b6-11e7-b58e-df773034efe4=cb76ee62-db17-11e8-bb24-e322d5547169; wltoken=2dac12af5bfe5c47; wluserid=596443; wlnickname=%E4%B8%AA%E4%BA%BA%E4%B8%AD%E5%BF%83; pageViewNum=16',
'pragma': 'no-cache',
'upgrade-insecure-requests': '',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
}
# url = "https://stock.tuchong.com/search?term={keyword}&use=0&type=2&layout=&sort=0&category=0&page={page}&size=200&search_from=head&exact=0&platform=weili&tp=&abtest=&royalty_free=0&option=&has_person=2&face_num=1&gender=0&age=&racial=".format(keyword=keyword,page=page,)
url = "https://stock.tuchong.com/search?id=&term={keyword}&no_overwrite=&use=0&type=&layout=&sort=0&category=0&size=100&exact=0&platform=weili&tp=&abtest=&royalty_free=0&image_source=&option=&has_person=0&face_num=&gender=0&age=&racial=&samemodel=0".format(keyword=keyword, page=page, )
print("48: "+url) while True:
try:
res = requests.get(url, headers=headers_visitContent)
break
except:
time.sleep(30)
imgIds = re.findall(r'{"imageId":"(.*?)"', res.text)
for imgId in imgIds:
downPic(savePath, keyword, imgId) if __name__ == '__main__': keywords = ["关键词",]# 道路标识牌环岛路
savePath = "保存路径" if not os.path.exists(savePath):
os.makedirs(savePath)
for keyword in keywords:
visitContent(keyword, savePath) # 55307393390740003 道路标识牌环岛路 id=131600804460241346&term=禁止直行 id=257496294632980656&term=减速让行交通标志 ?id=248510905222169041&term=停车让行
#id=453257691392639896&term=停车让行 263558615201480875&term=城市红绿灯 id=79053073577827598&term=蓝底圆牌路标 id=131636916545257789&term=中国城市路标
#id=457311144087650880&term=中国城市路标 id=131549428061446425&term=中国城市路标 131573170640654291&term=中国城市路标
# id=131623610736582305&term=中国城市路标 id=131609248365945763&term=中国城市路标 #https://stock.tuchong.com/search?id=263558615201480875&term=%E7%BA%A2%E7%BB%BF%E7%81%AF%E8%B7%AF%E5%8F%A3&use=0&type=&layout=&sort=0&category=0&page=1&size=100&exact=0&platform=weili&tp=&abtest=&royalty_free=0&option=&has_person=0&face_num=&gender=0&age=&racial=&samemodel=0
python根据关键字以及id值爬取图虫网上高质量大图的更多相关文章
- python3爬虫-通过requests爬取图虫网
import requests from fake_useragent import UserAgent from requests.exceptions import Timeout from ur ...
- 爬虫 Scrapy框架 爬取图虫图片并下载
items.py,根据需求确定自己的数据要求 # -*- coding: utf-8 -*- # Define here the models for your scraped items # # S ...
- 爬取图虫网 示例网址 https://wangxu.tuchong.com/23892889/
#coding=gbk import requests from fake_useragent import UserAgent from lxml import etree import urlli ...
- python网络爬虫第三弹(<爬取get请求的页面数据>)
一.urllib库 urllib是python自带的一个用于爬虫的库,其主要作用就是通过代码模拟浏览器发送请求,其常被用到的子模块在 python3中的为urllib.request 和 urllib ...
- Python爬虫学习三------requests+BeautifulSoup爬取简单网页
第一次第一次用MarkDown来写博客,先试试效果吧! 昨天2018俄罗斯世界杯拉开了大幕,作为一个伪球迷,当然也得为世界杯做出一点贡献啦. 于是今天就编写了一个爬虫程序将腾讯新闻下世界杯专题的相关新 ...
- 初识python 之 爬虫:使用正则表达式爬取“糗事百科 - 文字版”网页数据
初识python 之 爬虫:使用正则表达式爬取"古诗文"网页数据 的兄弟篇. 详细代码如下: #!/user/bin env python # author:Simple-Sir ...
- Node JS爬虫:爬取瀑布流网页高清图
原文链接:Node JS爬虫:爬取瀑布流网页高清图 静态为主的网页往往用get方法就能获取页面所有内容.动态网页即异步请求数据的网页则需要用浏览器加载完成后再进行抓取.本文介绍了如何连续爬取瀑布流网页 ...
- Python爬虫初探 - selenium+beautifulsoup4+chromedriver爬取需要登录的网页信息
目标 之前的自动答复机器人需要从一个内部网页上获取的消息用于回复一些问题,但是没有对应的查询api,于是想到了用脚本模拟浏览器访问网站爬取内容返回给用户.详细介绍了第一次探索python爬虫的坑. 准 ...
- python爬虫调用搜索引擎及图片爬取实战
实战三-向搜索引擎提交搜索请求 关键点:利用搜索引擎提供的接口 百度的接口:wd="要搜索的内容" 360的接口:q="要搜索的内容" 所以我们只要把我们提交给 ...
随机推荐
- ACM菜鸡退役帖——ACM究竟给了我什么?
这个ACM退役帖,诸多原因(一言难尽...),终于决定在我大三下学期开始的时候写出来.下面说两个重要的原因. 其一是觉得菜鸡的ACM之旅没人会看的,但是新学期开始了,总结一下,只为了更好的出发吧. 其 ...
- 【Vue.js】基于vue的实时搜索,在结果中高亮显示关键词
一.搜素效果如下: 二.核心 1)利用oninput属性来触发搜素功能 2)利用RegExp来对字符串来全局匹配关键字,利用replace方法来对匹配的关键字进行嵌入高亮的<span class ...
- 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)
HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...
- pxe+http+kickstart实验原理
1.说明 所谓的PXE是Preboot Execution Environment的缩写,字面上的意思是开机前的执行环境. 要实现pxe,至少需要3个服务 2.流程 注意:全部用的udp封装 1)cl ...
- shell编程基础(七): 处理文件命令sed与awk
一.sed(以行为单位处理文件) sed意为流编辑器(Stream Editor),在Shell脚本和Makefile中作为过滤器使用非常普遍,也就是把前一个程序的输出引入sed的输入,经过一系列编辑 ...
- zepto 事件分析4(事件队列)
前面分析了zepto的事件绑定,接下来分析事件解绑,先看一下zepto中解绑的off方法: $.fn.off = function(event, selector, callback){ var $t ...
- .Net C#域账号登陆验证
//获取登陆页输入的域账号.密码 string domainIP = ""; //域IP string userAccount = ""; //域账号 stri ...
- Layui table 组件的使用:初始化加载数据、数据刷新表格、传参数
背景 笔者之前一直使用 bootstrap table ,因为当前项目中主要使用 Layui 框架,于是也就随了 Layui table ,只是在使用的时候出现了一些问题,当然也是怪自己不熟悉的锅吧! ...
- 什么是 Native、Web App、Hybrid、React Native 和 Weex?(转载)
什么是 Native.Web App.Hybrid.React Native 和 Weex? 来源:zwwill_木羽 segmentfault.com/a/1190000011154120 一句 ...
- 44.Linux君正X1000-添加st7789v显示
由于板子LCD旧屏是ili9335型号的,旧屏有时候会断货,如果断货则使用一个st7789v型号的LCD 它们两个屏的区别在于初始化屏的参数不同,引脚都一样,也就是说需要使板子同时支持ili9335型 ...