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="要搜索的内容" 所以我们只要把我们提交给 ...
随机推荐
- 网络协议抓包分析——ARP地址解析协议
前言 计算机之间可以相互通信的前提是要知道对方的地址,才可以发送信息给其他计算机,就像别人要联系你也得先知道你的电话号码一样.这里的地址因为网络分层的原因就包括IP地址和MAC地址(即网卡地址.硬件地 ...
- Go基础系列:Go接口
接口用法简介 接口(interface)是一种类型,用来定义行为(方法). type Namer interface { my_method1() my_method2(para) my_method ...
- 翻译:last_value()函数(已提交到MariaDB官方手册)
本文为mariadb官方手册:LAST_VALUE()的译文. 原文:https://mariadb.com/kb/en/last_value/我提交到MariaDB官方手册的译文:https://m ...
- Linux C 实现一个简单的线程池
线程池的定义 线程池是一种多线程处理形式,处理过程中将任务添加到队列,然后在创建线程后自动启动这些任务.线程池线程都是后台线程.每个线程都使用默认的堆栈大小,以默认的优先级运行,并处于多线程单元中.如 ...
- Jenkins+Git+Gitlab+Ansible实现持续集成自动化部署静态网站(一)--技术流ken
前言 在之前已经写了关于Git,Gitlab以及Ansible的两篇博客<Git+Gitlab+Ansible剧本实现一键部署Nginx--技术流ken>,<Git+Gitlab+A ...
- spark高可用集群搭建及运行测试
文中的所有操作都是在之前的文章spark集群的搭建基础上建立的,重复操作已经简写: 之前的配置中使用了master01.slave01.slave02.slave03: 本篇文章还要添加master0 ...
- TCP&UDP&Socket讲解(上)
这两天我将整理TCP&UDP&Socket,大约花大家10-15分钟之间,希望本篇文章让大家对TCP使用的理解提高一个层次. 建议大家拿出纸和笔,画一下!!! 一.TCP 1. TCP ...
- Python进阶笔记
列表生成式 函数的参数类型 lambda函数 map, reduce, filter, sorted函数 eval, exec, join, zip函数 itertools中的函数 copy与deep ...
- [转] 使用slim3快速开发RESTful API
本文转自:https://blog.csdn.net/u011250882/article/details/50101599 版权声明:本文为博主原创文章,转载请注明出处和作者名,尊重别人也是尊重自己 ...
- C# 从Excel中读取条码
条形码的应用三------从Excel文件中读取条形码 介绍 上一篇文章,我向大家展示了生成多个条形码并存储到Excel文件中的一个方法.后来我又有了个想法:既然条码插入到excel中了,我可不可以从 ...