爬全景网壁纸(反爬机制Referer)

news/2024/11/23 3:23:37/

url以及参数:

在这里插入图片描述

https://www.quanjing.com/Handler/SearchUrl.ashx?t=1509&callback=searchresult&q=%E5%A3%81%E7%BA%B8&stype=1&pagesize=100&pagenum=1&imageType=2&imageColor=&brand=&imageSType=&fr=1&sortFlag=1&imageUType=&btype=&authid=&_=1597160644966
t: 1509
callback: searchresult
q: 壁纸
stype: 1
pagesize: 100
pagenum: 1
imageType: 2
imageColor: 
brand: 
imageSType: 
fr: 1
sortFlag: 1
imageUType: 
btype: 
authid: 
_: 1597160644966

爬取全景网壁纸图片,该网站增加了反爬机制Referer,在url参数上添加了回调函数callback=searchresult
破解方法:在请求头添加Referer,具体代码如下:

#添加Referer,用来破解Referer反爬机制
header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52','Referer': 'https://www.quanjing.com/search.aspx?q=%E5%A3%81%E7%BA%B8'
}
respone=requests.get(url=url1,headers=header)

添加了异步下载,全部代码如下:

# -*-coding:utf-8 -*-
import asyncio
import requests
import json
from lxml import etree
import aiohttpurl='https://www.quanjing.com/search.aspx?'
url1='https://www.quanjing.com/Handler/SearchUrl.ashx?t=1509&callback=searchresult&q=%E5%A3%81%E7%BA%B8&stype=1&pagesize=100&pagenum=1&imageType=2&imageColor=&brand=&imageSType=&fr=1&sortFlag=1&imageUType=&btype=&authid=&_=1597160644966'#添加Referer,用来破解Referer反爬机制
header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52','Referer': 'https://www.quanjing.com/search.aspx?q=%E5%A3%81%E7%BA%B8'
}
respone=requests.get(url=url1,headers=header)#爬取结果:searchresult({"pageindex":1,"pagecount":554981,"recordcount":55498019,"correlkeywords":"","execstr":"","imglist":[{"pic_id":"ul2851-8520","catalogid":"ul2851","copyright":"RF","caption":"漂亮,海滩,海洋,棕榈树","height":"3648","width":"5472","imgurl":"http://dpic.tiankong.com/e0/5h/QJ6665069082.jpg","imgCode":"qj6665069082"},{"pic_id":"pm0120-2144gq","catalogid":"pm0120","copyright":"RF","caption":"自然,背景","height":"443","width":"640","imgurl":"http://dpic.tiankong.com/us/tz/QJ6565583877.jpg","imgCode":"qj6565583877"},{"pic_id":"mf822-07840822","catalogid":"mf100","copyright":"RM","caption":"","height":"3744","width":"5616","imgurl":"http://dpic.tiankong.com/un/ad/QJ6161631717.jpg","imgCode":"qj6161631717"},{"pic_id":"tpgrf-sisteron003","catalogid":"chineseview075","copyright":"RF","caption":"sisteron","height":"407","width":"640","imgurl":"http://dpic.tiankong.com/16/9a/QJ6123769966.jpg","imgCode":"qj6123769966"},{"pic_id":"ph1760-p00135","catalogid":"ph032","copyright":"RM","caption":"","height":"4830","width":"7117","imgurl":"http://dpic.tiankong.com/vl/tg/QJ6334439001.jpg","imgCode":"qj6334439001"},{"pic_id":"tpgrf-usa2010-0043","catalogid":"chineseview075","copyright":"RF","caption":"","height":"2848","width":"4288","imgurl":"http://dpic.tiankong.com/g8/p5/QJ6632000575.jpg","imgCode":"qj6632000575"},{"pic_id":"qj8626733361","catalogid":"QJ86267","copyright":"RF","caption":"城市,未来,摩天大楼,科幻,抽象","height":"479","width":"640","imgurl":"http://dpic.tiankong.com/kh/s6/QJ8626733361.jpg","imgCode":"qj8626733361"},{"pic_id":"412-02651","catalogid":"caia_rf001","copyright":"RF","caption":"特写,紫色,八仙花属,花","height":"428","width":"640","imgurl":"http://dpic.tiankong.com/8h/bv/QJ6127671585.jpg","imgCode":"qj6127671585"},{"pic_id":"ph8324-p00061","catalogid":"ph154","copyright":"RM","caption":"海底","height":"3100","width":"4537","imgurl":"http://dpic.tiankong.com/ki/c8/QJ9106922833.jpg","imgCode":"qj9106922833"},{"pic_id":"min00429507","catalogid":"minden005","copyright":"RM","caption":"南极","height":"425","width":"640","imgurl":"http://dpic.tiankong.com/9t/lp/QJ6886640372.jpg","imgCode":"qj6886640372"},{"pic_id":"fsi-314024","catalogid":"fsi001","copyright":"RF","caption":"彩虹,天空,高处,千禧轮,伦敦,英格兰","height":"442","width":"640","imgurl":"http://dpic.tiankong.com/l2/3x/QJ6759064434.jpg","imgCode":"qj6759064434"},{"pic_id":"ph9701-p00020","catalogid":"ph222","copyright":"RM","caption":"星空","height":"3648","width":"5472","imgurl":"http://dpic.tiankong.com/vf/03/QJ9123938457.jpg","imgCode":"qj9123938457"},{"pic_id":"mf700-01587188","catalogid":"mf037","copyright":"RM","caption":"","height":"3401","width":"5100","imgurl":"http://dpic.tiankong.com/7s/lr/QJ6142216204.jpg","imgCode":"qj6142216204"},{"pic_id":"yt-p0045820","catalogid":"Chineseview024","copyright":"RF","caption":"天坛祈年殿","height":"3386","width":"5120","imgurl":"http://dpic.tiankong.com/8e/k1/QJ6977701697.jpg","imgCode":"qj6977701697"},{"pic_id":"us33-pad0058","catalogid":"danitarm028","copyright":"RM","caption":"色彩折射,间歇泉,黄石国家公园,怀俄明,美国","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/9t/tz/QJ6892740340.jpg","imgCode":"qj6892740340"},{"pic_id":"1t-2058","catalogid":"chineseview156","copyright":"RM","caption":"南极","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/ws/r0/QJ6104306716.jpg","imgCode":"qj6104306716"},{"pic_id":"nature1399395","catalogid":"nature019","copyright":"RM","caption":"","height":"2848","width":"4288","imgurl":"http://dpic.tiankong.com/5v/3x/QJ8133747512.jpg","imgCode":"qj8133747512"},{"pic_id":"qj9107316620","catalogid":"QJ91073","copyright":"RF","caption":"紫色","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/7w/cz/QJ9107316620.jpg","imgCode":"qj9107316620"},{"pic_id":"ph5417-5427","catalogid":"chineseview146","copyright":"RM","caption":"","height":"3840","width":"5760","imgurl":"http://dpic.tiankong.com/sc/0j/QJ6129893600.jpg","imgCode":"qj6129893600"},{"pic_id":"qj8604253176","catalogid":"QJ86042","copyright":"RF","caption":"爱心","height":"423","width":"640","imgurl":"http://dpic.tiankong.com/5g/x9/QJ8604253176.jpg","imgCode":"qj8604253176"},{"pic_id":"sps1317-410","catalogid":"sps014","copyright":"RM","caption":"","height":"3340","width":"5072","imgurl":"http://dpic.tiankong.com/5m/pr/QJ8193232248.jpg","imgCode":"qj8193232248"},{"pic_id":"qj8903621131","catalogid":"QJ89036","copyright":"RF","caption":"特写,羽毛,羽毛掸,使用","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/m0/xf/QJ8903621131.jpg","imgCode":"qj8903621131"},{"pic_id":"ph1979-p00076","catalogid":"ph212","copyright":"RM","caption":"星空","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/ih/gz/QJ9123069226.jpg","imgCode":"qj9123069226"},{"pic_id":"wavebrak518595","catalogid":"wavebreak036","copyright":"RF","caption":"漂亮,女人,放松,吊床,看镜头,微笑,海滩","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/bh/fx/QJ6118379830.jpg","imgCode":"qj6118379830"},{"pic_id":"qj8299771849","catalogid":"QJ82997","copyright":"RF","caption":"数码,绘画,风格,油画,情侣,站立,看,日落,自然美","height":"427","width":"640","imgurl":"http://dpic.tiankong.com/hx/j3/QJ8299771849.jpg","imgCode":"qj8299771849"},{"pic_id":"iblaza04236169","catalogid":"ibrm059","copyright":"RM","caption":"仙女,木头","height":"378","width":"640","imgurl":"http://dpic.tiankong.com/id/er/QJ6583675082.jpg","imgCode":"qj6583675082"},{"pic_id":"mf700-00025312","catalogid":"mf001","copyright":"RM","caption":"肖像,西伯利亚虎,幼兽","height":"436","width":"640","imgurl":"http://dpic.tiankong.com/39/kd/QJ6319982216.jpg","imgCode":"qj6319982216"},{"pic_id":"tpgrm-top10060001a0315_cr","catalogid":"chineseview063","copyright":"RM","caption":"特写,露珠,树叶","height":"457","width":"640","imgurl":"http://dpic.tiankong.com/cw/m0/QJ6531067783.jpg","imgCode":"qj6531067783"},{"pic_id":"ul0357-4987","catalogid":"ul0357","copyright":"RF","caption":"两只,手,拿着,葡萄园,拉沃,区域,瑞士","height":"1660","width":"2500","imgurl":"http://dpic.tiankong.com/dd/ja/QJ6735099078.jpg","imgCode":"qj6735099078"},{"pic_id":"533-p00441","catalogid":"ph258","copyright":"RM","caption":"土耳其,亚热,气球","height":"5504","width":"8256","imgurl":"http://dpic.tiankong.com/hl/hs/QJ9126815305.jpg","imgCode":"qj9126815305"},{"pic_id":"ph5417-7652","catalogid":"chineseview146","copyright":"RM","caption":"","height":"3840","width":"5760","imgurl":"http://dpic.tiankong.com/xt/us/QJ6220158718.jpg","imgCode":"qj6220158718"},{"pic_id":"iblpia02186995","catalogid":"ibrm019","copyright":"RM","caption":"拳师狗,小狗,张嘴,肖像","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/0f/1w/QJ6289242256.jpg","imgCode":"qj6289242256"},{"pic_id":"mf700-02231888","catalogid":"mf040","copyright":"RM","caption":"","height":"3400","width":"5100","imgurl":"http://dpic.tiankong.com/k8/eu/QJ6208809009.jpg","imgCode":"qj6208809009"},{"pic_id":"ph10680-p00016","catalogid":"ph256","copyright":"RM","caption":"月球小镇日出","height":"3744","width":"5616","imgurl":"http://dpic.tiankong.com/hi/sj/QJ9126707529.jpg","imgCode":"qj9126707529"},{"pic_id":"mf700-00074549","catalogid":"mf010","copyright":"RM","caption":"星球,太空,奇幻景观","height":"321","width":"640","imgurl":"http://dpic.tiankong.com/dj/h1/QJ6473328550.jpg","imgCode":"qj6473328550"},{"pic_id":"ph7675-p00419","catalogid":"ph157","copyright":"RM","caption":"彩色气球","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/1u/2c/QJ9108188334.jpg","imgCode":"qj9108188334"},{"pic_id":"ph1156-3121","catalogid":"chineseview154","copyright":"RM","caption":"","height":"2732","width":"4096","imgurl":"http://dpic.tiankong.com/ed/wt/QJ6168506586.jpg","imgCode":"qj6168506586"},{"pic_id":"qj9109706996","catalogid":"QJ91097","copyright":"RF","caption":"法国,里维埃拉,戛纳,日出","height":"425","width":"640","imgurl":"http://dpic.tiankong.com/9c/db/QJ9109706996.jpg","imgCode":"qj9109706996"},{"pic_id":"qj8428400877","catalogid":"QJ84284","copyright":"RF","caption":"拉布拉多犬,可爱,宠物","height":"423","width":"640","imgurl":"http://dpic.tiankong.com/zc/7x/QJ8428400877.jpg","imgCode":"qj8428400877"},{"pic_id":"tpgrf-camargue001","catalogid":"chineseview075","copyright":"RF","caption":"","height":"2292","width":"3980","imgurl":"http://dpic.tiankong.com/k9/hn/QJ6115796625.jpg","imgCode":"qj6115796625"},{"pic_id":"caia412-15903","catalogid":"caia_rf003","copyright":"RF","caption":"","height":"3632","width":"4841","imgurl":"http://dpic.tiankong.com/mw/bd/QJ6820158347.jpg","imgCode":"qj6820158347"},{"pic_id":"qj8634286945","catalogid":"QJ86342","copyright":"RF","caption":"卡昂,天际线,水彩,背景","height":"480","width":"640","imgurl":"http://dpic.tiankong.com/82/0h/QJ8634286945.jpg","imgCode":"qj8634286945"},{"pic_id":"qj8665701886","catalogid":"QJ86657","copyright":"RF","caption":"油画,风景,彩色,秋天,树,抽象画面,树林,黄色,红叶,自然,手绘,印象派,风格","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/xn/c3/QJ8665701886.jpg","imgCode":"qj8665701886"},{"pic_id":"mf700-02053470","catalogid":"mf040","copyright":"RM","caption":"鸟,线缆,温哥华,不列颠哥伦比亚省,加拿大","height":"425","width":"640","imgurl":"http://dpic.tiankong.com/jc/i7/QJ8188733693.jpg","imgCode":"qj8188733693"},{"pic_id":"ibxvda00308405","catalogid":"ibrf006","copyright":"RF","caption":"羽毛","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/jl/ce/QJ8169266781.jpg","imgCode":"qj8169266781"},{"pic_id":"bji90010220","catalogid":"bjisub008","copyright":"RF","caption":"梦幻城市","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/xg/jb/QJ6379239422.jpg","imgCode":"qj6379239422"},{"pic_id":"bji72000143","catalogid":"bjisub009","copyright":"RF","caption":"沙漠骆驼队插画","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/ha/5m/QJ6889529417.jpg","imgCode":"qj6889529417"},{"pic_id":"an02-pso0345","catalogid":"danitarm012","copyright":"RM","caption":"南极,巴布亚企鹅","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/cw/g6/QJ6147932039.jpg","imgCode":"qj6147932039"},{"pic_id":"ul0057-8946","catalogid":"ul0057","copyright":"RF","caption":"傍晚,上方,地点,干草包","height":"3168","width":"4752","imgurl":"http://dpic.tiankong.com/xd/x1/QJ6679918814.jpg","imgCode":"qj6679918814"},{"pic_id":"pm0178-7705qo","catalogid":"pm0178","copyright":"RF","caption":"","height":"4007","width":"5541","imgurl":"http://dpic.tiankong.com/ej/7e/QJ6657225658.jpg","imgCode":"qj6657225658"},{"pic_id":"mf700-02428473","catalogid":"mf044","copyright":"RM","caption":"约克郡溪谷国家公园,约克郡,英格兰","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/mk/tj/QJ6401482283.jpg","imgCode":"qj6401482283"},{"pic_id":"pm0049-3457ek","catalogid":"pm0049","copyright":"RF","caption":"花,壁纸","height":"425","width":"640","imgurl":"http://dpic.tiankong.com/nx/ir/QJ8182737871.jpg","imgCode":"qj8182737871"},{"pic_id":"qj8528732414","catalogid":"QJ85287","copyright":"RF","caption":"美景,阴天,漂亮,自然,背景","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/xc/39/QJ8528732414.jpg","imgCode":"qj8528732414"},{"pic_id":"ghi-jcalv00398","catalogid":"glass002","copyright":"RM","caption":"旋转,美女,海洋,背景","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/m8/31/QJ6506881067.jpg","imgCode":"qj6506881067"},{"pic_id":"QJ5100165184","catalogid":"QJ51001","copyright":"RF","caption":"内蒙古公路美景","height":"484","width":"725","imgurl":"http://dpic.tiankong.com/sa/bw/QJ5100165184.jpg","imgCode":"qj5100165184"},{"pic_id":"pm0144-2844pk","catalogid":"pm0144","copyright":"RF","caption":"自然,背景","height":"472","width":"640","imgurl":"http://dpic.tiankong.com/dz/d1/QJ6626417062.jpg","imgCode":"qj6626417062"},{"pic_id":"mf824-02887759","catalogid":"mf068","copyright":"RM","caption":"冰激凌","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/na/5c/QJ6420684879.jpg","imgCode":"qj6420684879"},{"pic_id":"nature1482259","catalogid":"nature016","copyright":"RM","caption":"三个,可爱,幼仔,兔子,排列","height":"392","width":"640","imgurl":"http://dpic.tiankong.com/pz/98/QJ6255858099.jpg","imgCode":"qj6255858099"},{"pic_id":"ul2740-3308","catalogid":"ul2740","copyright":"RF","caption":"水滴","height":"3312","width":"5064","imgurl":"http://dpic.tiankong.com/00/1a/QJ6330333712.jpg","imgCode":"qj6330333712"},{"pic_id":"ibxarc00104478","catalogid":"ibrf009","copyright":"RF","caption":"气泡","height":"419","width":"640","imgurl":"http://dpic.tiankong.com/hx/ex/QJ6330215369.jpg","imgCode":"qj6330215369"},{"pic_id":"wavebreak460400","catalogid":"wavebreak032","copyright":"RF","caption":"心形,气球","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/mk/bx/QJ6796827179.jpg","imgCode":"qj6796827179"},{"pic_id":"533-p00436","catalogid":"ph258","copyright":"RM","caption":"土耳其,亚热,气球","height":"5504","width":"8256","imgurl":"http://dpic.tiankong.com/50/hs/QJ9126815256.jpg","imgCode":"qj9126815256"},{"pic_id":"pm0130-1521wt","catalogid":"pm0130","copyright":"RF","caption":"创意","height":"414","width":"640","imgurl":"http://dpic.tiankong.com/ml/v7/QJ6709208651.jpg","imgCode":"qj6709208651"},{"pic_id":"qj8806425294","catalogid":"QJ88064","copyright":"RF","caption":"醒,龙","height":"450","width":"640","imgurl":"http://dpic.tiankong.com/1b/51/QJ8806425294.jpg","imgCode":"qj8806425294"},{"pic_id":"qj8335469393","catalogid":"QJ83354","copyright":"RF","caption":"蝠鲼,光线,飞,多云,世界,概念,展示,阴天,插画,绘画","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/ke/ii/QJ8335469393.jpg","imgCode":"qj8335469393"},{"pic_id":"mintrm-0812","catalogid":"mint_rm001","copyright":"RM","caption":"雨林,植被,棕榈树,茂密,叶子,温室,植物园,美国","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/gg/ik/QJ6523759615.jpg","imgCode":"qj6523759615"},{"pic_id":"mf700-00043747","catalogid":"mf004","copyright":"RM","caption":"球体,金字塔","height":"436","width":"640","imgurl":"http://dpic.tiankong.com/nl/is/QJ6397373007.jpg","imgCode":"qj6397373007"},{"pic_id":"na02-bjy0001","catalogid":"danitarm030","copyright":"RM","caption":"概念,恐龙,海洋,岸边,画廊","height":"449","width":"640","imgurl":"http://dpic.tiankong.com/lt/lk/QJ6520621810.jpg","imgCode":"qj6520621810"},{"pic_id":"pm0526-0359ud","catalogid":"pm0526","copyright":"RF","caption":"粉色","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/3x/lu/QJ6458362824.jpg","imgCode":"qj6458362824"},{"pic_id":"iblmsn00591495","catalogid":"ibrm011","copyright":"RM","caption":"天使","height":"428","width":"640","imgurl":"http://dpic.tiankong.com/i9/te/QJ8128388746.jpg","imgCode":"qj8128388746"},{"pic_id":"QJ7118889241","catalogid":"QJ71188","copyright":"RF","caption":"插画,图像,飞,大脑,自由,思考","height":"3392","width":"5184","imgurl":"http://dpic.tiankong.com/v3/36/QJ7118889241.jpg","imgCode":"qj7118889241"},{"pic_id":"us48-dgu0537","catalogid":"danita_rm010","copyright":"RM","caption":"","height":"3380","width":"5080","imgurl":"http://dpic.tiankong.com/bj/0g/QJ6123668406.jpg","imgCode":"qj6123668406"},{"pic_id":"ul2904-8664","catalogid":"ul2904","copyright":"RF","caption":"绿色","height":"3804","width":"5622","imgurl":"http://dpic.tiankong.com/xa/69/QJ6818499678.jpg","imgCode":"qj6818499678"},{"pic_id":"ibxrim00128728","catalogid":"ibrf008","copyright":"RF","caption":"黄色","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/rf/0c/QJ6744686741.jpg","imgCode":"qj6744686741"},{"pic_id":"qj8811189146","catalogid":"QJ88111","copyright":"RF","caption":"黄色,伞,亮黄色,黑色","height":"480","width":"640","imgurl":"http://dpic.tiankong.com/ew/fs/QJ8811189146.jpg","imgCode":"qj8811189146"},{"pic_id":"is09ap23v","catalogid":"cultura014","copyright":"RF","caption":"骡子,手包,葡萄酒杯,黄色","height":"479","width":"640","imgurl":"http://dpic.tiankong.com/ac/au/QJ8197933282.jpg","imgCode":"qj8197933282"},{"pic_id":"83-0145","catalogid":"CPS1","copyright":"RM","caption":"黄色,花","height":"2982","width":"4453","imgurl":"http://dpic.tiankong.com/66/lt/QJ6743115875.jpg","imgCode":"qj6743115875"},{"pic_id":"bji01991363","catalogid":"bjisub002","copyright":"RF","caption":"金色草原","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/29/7f/QJ6725710491.jpg","imgCode":"qj6725710491"},{"pic_id":"pm0328-7432fp","catalogid":"pm0328","copyright":"RF","caption":"火红,云","height":"425","width":"640","imgurl":"http://dpic.tiankong.com/fr/ll/QJ6131632804.jpg","imgCode":"qj6131632804"},{"pic_id":"qj9106031364","catalogid":"QJ91060","copyright":"RM","caption":"北极光","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/f5/sd/QJ9106031364.jpg","imgCode":"qj9106031364"},{"pic_id":"qj8204422012","catalogid":"QJ82044","copyright":"RF","caption":"火山,湖,冰岛,景色,风景,日落","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/w2/am/QJ8204422012.jpg","imgCode":"qj8204422012"},{"pic_id":"ul0760-0897","catalogid":"ul0760","copyright":"RF","caption":"大教堂,雷克雅未克,冰岛","height":"7647","width":"7727","imgurl":"http://dpic.tiankong.com/n2/5g/QJ6630138735.jpg","imgCode":"qj6630138735"},{"pic_id":"qj8914338103","catalogid":"QJ89143","copyright":"RF","caption":"风车,郁金香,地点,荷兰,漂亮,日落","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/th/s7/QJ8914338103.jpg","imgCode":"qj8914338103"},{"pic_id":"ct-1323","catalogid":"chineseview051","copyright":"RF","caption":"中国元素","height":"355","width":"640","imgurl":"http://dpic.tiankong.com/k9/j6/QJ6741423761.jpg","imgCode":"qj6741423761"},{"pic_id":"rad600-02886094s","catalogid":"rad006","copyright":"RF","caption":"干草,地点","height":"422","width":"640","imgurl":"http://dpic.tiankong.com/px/76/QJ6971044819.jpg","imgCode":"qj6971044819"},{"pic_id":"AFM-ic-08604","catalogid":"afl002","copyright":"RM","caption":"","height":"3508","width":"5150","imgurl":"http://dpic.tiankong.com/z7/vd/QJ6137537933.jpg","imgCode":"qj6137537933"},{"pic_id":"afd-04-01-04987","catalogid":"afl005","copyright":"RM","caption":"湖","height":"510","width":"640","imgurl":"http://dpic.tiankong.com/86/1c/QJ6972225633.jpg","imgCode":"qj6972225633"},{"pic_id":"qj8889655078","catalogid":"QJ88896","copyright":"RF","caption":"海贝,抽象画面,晚霞","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/dv/te/QJ8889655078.jpg","imgCode":"qj8889655078"},{"pic_id":"27-1220","catalogid":"chineseview019","copyright":"RM","caption":"","height":"3328","width":"4992","imgurl":"http://dpic.tiankong.com/ak/21/QJ6898019874.jpg","imgCode":"qj6898019874"},{"pic_id":"mf855-03254967","catalogid":"mf062","copyright":"RM","caption":"海湾大桥,横滨,日本","height":"491","width":"640","imgurl":"http://dpic.tiankong.com/ap/dd/QJ6973233762.jpg","imgCode":"qj6973233762"},{"pic_id":"hokkaido50044421","catalogid":"hokkaido003","copyright":"RM","caption":"客机,晚霞","height":"480","width":"640","imgurl":"http://dpic.tiankong.com/16/8e/QJ6743196782.jpg","imgCode":"qj6743196782"},{"pic_id":"chna006100","catalogid":"afl008","copyright":"RM","caption":"和歌山,日本","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/0g/9v/QJ6947656688.jpg","imgCode":"qj6947656688"},{"pic_id":"qj8737793324","catalogid":"QJ87377","copyright":"RF","caption":"山,草地,青草,晚霞","height":"428","width":"640","imgurl":"http://dpic.tiankong.com/7h/hs/QJ8737793324.jpg","imgCode":"qj8737793324"},{"pic_id":"hokkaido50044420","catalogid":"hokkaido003","copyright":"RM","caption":"客机,晚霞","height":"480","width":"640","imgurl":"http://dpic.tiankong.com/5a/aw/QJ6963464280.jpg","imgCode":"qj6963464280"},{"pic_id":"mf855-03254870","catalogid":"mf062","copyright":"RM","caption":"风车,康斯艾格拉,拉曼查,西班牙","height":"499","width":"640","imgurl":"http://dpic.tiankong.com/3w/xu/QJ6938622856.jpg","imgCode":"qj6938622856"},{"pic_id":"nature1435861","catalogid":"nature010","copyright":"RM","caption":"小,水母,下方,表面,海洋,保护区,波托菲诺,区域,码头,利古里亚,意大利,地中海","height":"423","width":"640","imgurl":"http://dpic.tiankong.com/cd/d2/QJ6526179527.jpg","imgCode":"qj6526179527"},{"pic_id":"bji61600900","catalogid":"bjisub009","copyright":"RF","caption":"汽车广告背景图","height":"484","width":"725","imgurl":"http://dpic.tiankong.com/9r/a2/QJ6931974836.jpg","imgCode":"qj6931974836"},{"pic_id":"mts05145612","catalogid":"mtsrm003","copyright":"RM","caption":"柏油路,路灯","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/08/9f/QJ6359765040.jpg","imgCode":"qj6359765040"},{"pic_id":"bji0138_0053","catalogid":"bjisub001","copyright":"RF","caption":"红叶","height":"426","width":"640","imgurl":"http://dpic.tiankong.com/x2/i3/QJ6605253502.jpg","imgCode":"qj6605253502"},{"pic_id":"QJ7109895412","catalogid":"QJ71098","copyright":"RF","caption":"雨","height":"4000","width":"6000","imgurl":"http://dpic.tiankong.com/9c/v0/QJ7109895412.jpg","imgCode":"qj7109895412"}]})
#将获取到的数据进行切片处理,并字典化
dict_text=json.loads(respone.text[13:-1])
#取出图片列表
imglist=dict_text['imglist']
#取出图片id跟url两个参数。
url_list=[]
for li in imglist:#将图片的信息字典化dic={'id':li['pic_id'],'url':li['imgurl']}url_list.append(dic)#异步函数处理:
async def down_img(dic):imgname=dic['id']+'.jpg'filtpath="./images/"+imgnameprint(imgname+'下载开始')url=dic['url']async with aiohttp.ClientSession() as session:async with session.get(url) as respone:#图片、视频只能用read()方法,同时,必须手动挂起awaitimg_data= await respone.read()f=open(filtpath,'wb')f.write(img_data)f.close()print(imgname+"下载完毕")
tasks=[]
for dic_url in url_list:c=down_img(dic_url)#声明一个task对象task=asyncio.ensure_future(c)#将task任务对象添加到任务列表中tasks.append(task)
#声明一个循环事件,用来执行任务
loop=asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))

执行结果如下:
在这里插入图片描述


http://www.ppmy.cn/news/119445.html

相关文章

ubuntu 12.04亮度无法调节和无法保存屏幕亮度解决办法(echo_brightness)

经过多次更改失败重装后终于在官网的answers找到了解决办法:原文链接 http://askubuntu.com/questions/3841/desktop-doesnt-remember-brightness-settings-after-a-reboot 1、解决reboot后无法保存屏幕亮度: [cpp] view plaincopy sudo gedit /etc/rc.l…

【一千个论文合集】计算机科学的26个细分领域近年必读论文集合

文章目录 1.机器学习2.计算机视觉3.自然语言处理4.数据挖掘5.机器人6.知识工程7.模式识别8.信息检索与推荐9.数据库10.人机交互11.计算机图形学12.多媒体13.可视化14.数据科学15.安全与隐私16.计算科学17.计算机工程18.软件工程19.计算机体系结构20.实时和嵌入式系统21.程序设计…

释放你的C盘,别让 win7 C盘空间越来越小?

用了WIN7 64位旗舰版 4830TG一段时间了,刚买回来那会儿,故意给C盘(系统盘)留了80G,而且什么东西都从不装到C盘,过了一段时间,发现C盘居然变小了太多了,只剩下30G,乖乖&am…

Windows7 C盘空间越来越小处理方法

(本文源自网络,作者不详) 释放你的C盘,别让 win7 C盘空间越来越小? 用了WIN7 64位旗舰版 4830TG一段时间了,刚买回来那会儿,故意给C盘(系统盘)留了80G,而且什么东西都从不装到C盘&a…

vs2008gridview自带删除功能代码怎么实现

整形(不可变,存储一个值) 对于int类型的解释 赋值操作 转换操作,如下图所示,如果转换的是number,int括号里面可以为整形也可为浮点型,如果转换的是str,括号里面的字符串必须只能包含…

直流屏电源模块GF22007-2高频充电模块R22007

直流屏充电模块GF22007-2电源模块,整流模块GF22007-2,GF22010-3,GF22005-2,GF11010-2 英可瑞TG4820系列TG4820-2 立式 TG4820-5卧式 48V 20A TG4830系列 TG4830-2立式 TG4830-5卧式 48V 30A TG4840立式 TG4850卧式 48V 50A整流…

笔记本分类大全

有人说2012年整机行业很“冷”,有人说2012年整机行业利润越来越低了,有人说2012年将是整机行业变革的一年。而笔者却看到了这样的2012 年……在2012年英特尔推出了第三代智能处理器,随之而来的是各大厂商的更新换代新品齐出;在201…

价差100元 性能相当 蓝宝HD4830白金版 PK 9800GT显卡

价差100元 性能相当 蓝宝HD4830白金版 PK 9800GT显卡 作者:TG 优点:采用HD4850白金版一样的PCB及用料,非常强悍 缺点:如果带上HDMI接口就更完美了 咨询电话:020-38886993 NVIDIA的9800GT降价到799元以后,AMD显卡在中端…