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值爬取图虫网上高质量大图的更多相关文章

  1. python3爬虫-通过requests爬取图虫网

    import requests from fake_useragent import UserAgent from requests.exceptions import Timeout from ur ...

  2. 爬虫 Scrapy框架 爬取图虫图片并下载

    items.py,根据需求确定自己的数据要求 # -*- coding: utf-8 -*- # Define here the models for your scraped items # # S ...

  3. 爬取图虫网 示例网址 https://wangxu.tuchong.com/23892889/

    #coding=gbk import requests from fake_useragent import UserAgent from lxml import etree import urlli ...

  4. python网络爬虫第三弹(<爬取get请求的页面数据>)

    一.urllib库 urllib是python自带的一个用于爬虫的库,其主要作用就是通过代码模拟浏览器发送请求,其常被用到的子模块在 python3中的为urllib.request 和 urllib ...

  5. Python爬虫学习三------requests+BeautifulSoup爬取简单网页

    第一次第一次用MarkDown来写博客,先试试效果吧! 昨天2018俄罗斯世界杯拉开了大幕,作为一个伪球迷,当然也得为世界杯做出一点贡献啦. 于是今天就编写了一个爬虫程序将腾讯新闻下世界杯专题的相关新 ...

  6. 初识python 之 爬虫:使用正则表达式爬取“糗事百科 - 文字版”网页数据

    初识python 之 爬虫:使用正则表达式爬取"古诗文"网页数据 的兄弟篇. 详细代码如下: #!/user/bin env python # author:Simple-Sir ...

  7. Node JS爬虫:爬取瀑布流网页高清图

    原文链接:Node JS爬虫:爬取瀑布流网页高清图 静态为主的网页往往用get方法就能获取页面所有内容.动态网页即异步请求数据的网页则需要用浏览器加载完成后再进行抓取.本文介绍了如何连续爬取瀑布流网页 ...

  8. Python爬虫初探 - selenium+beautifulsoup4+chromedriver爬取需要登录的网页信息

    目标 之前的自动答复机器人需要从一个内部网页上获取的消息用于回复一些问题,但是没有对应的查询api,于是想到了用脚本模拟浏览器访问网站爬取内容返回给用户.详细介绍了第一次探索python爬虫的坑. 准 ...

  9. python爬虫调用搜索引擎及图片爬取实战

    实战三-向搜索引擎提交搜索请求 关键点:利用搜索引擎提供的接口 百度的接口:wd="要搜索的内容" 360的接口:q="要搜索的内容" 所以我们只要把我们提交给 ...

随机推荐

  1. 【Go】go get 自动代理

    原文链接:https://blog.thinkeridea.com/201903/go/go_get_proxy.html 最近发现技术交流群里很多人在询问 go get 墙外包失败的问题,大家给了很 ...

  2. Go基础系列:空接口

    空接口 空接口是指没有定义任何接口方法的接口.没有定义任何接口方法,意味着Go中的任意对象都可以实现空接口(因为没方法需要实现),任意对象都可以保存到空接口实例变量中. 空接口的定义方式: type ...

  3. 解读经典《C#高级编程》第七版 Page38-45.核心C#.Chapter2

    前言 控制流是语言中最基础的部分,我们不谈具体的细节,只讲讲一些关键和有趣的点. 01 流控制 条件语句:if, else if, else if语句的使用非常值得细讲,如何是好的使用习惯.有一点非常 ...

  4. C#通过虚方法实现方法重写—多态。

    class Program { //希望person存的是哪个类的对象就调用哪个类的方法 //第一步 将父类中对应方法家virtual关键字 变为虚方法(子类可重写) //子类中方法用override ...

  5. linux磁盘管理增加,扩容

    一.磁盘空间不足,添加新的磁盘 一般来说,当我们在服务上插入新的磁盘时,服务器是会对磁盘进行识别的.但是,有的时候服务器并没有对这些新插入的磁盘进行识别.这时,我们可以通过重启服务器,来使服务器重新加 ...

  6. c# 溢出上下文检测

    对于类型转换是否溢出可以用 checked和unchecked运算符 在unchecked上下文中会忽略溢出 在checked 会抛出异常 ; byte sb; sb = unchecked((byt ...

  7. 将汉字转化为拼音的js插件

    /*---------------------------------------------------------------- // 文件名:chinese2pinyin.js // 文件功能描 ...

  8. 【CSS】小妙招,各种问题总结方法处理

    1.实现div文字溢出自动省略号截取   overflow:hidden;  /*超过部分不显示*/   text-overflow:ellipsis;  /*超过部分用点点表示*/   white- ...

  9. 为什么redis是单线程的?速度还这么快

    为什么说Redis是单线程的? 为什么redis是单线程的?速度还这么快

  10. Netty 系列六(编解码器).

    一.概念 网络传输的单位是字节,如何将应用程序的数据转换为字节,以及将字节转换为应用程序的数据,就要说到到我们该篇介绍的编码器和解码器. 将应用程序的数据转换为网络格式,以及将网络格式转换为应用程序的 ...