python爬取百度长腿妹子图片,新手,不足的地方请多指教

import requests

url = "https://image.baidu.com/search/acjson?"
header = {
"User-Agent": "Mozilla/5.0(Windows NT 10.0; Win64; x64)AppleWebKit/537.36(KHTML, like Gecko)Chrome/90.0.4421.5Safari/537.36"
}
n=1
for s in range(10, 20):
param = {
"tn":"resultjson_com",
"logid":"7895948621809160179",
"ipn":"rj",
"ct":"201326592",
"is":"",
"fp":"result",
"queryWord":"长腿",
"cl":"2",
"lm":"-1",
"ie":"utf-8",
"oe":"utf-8",
"adpicid":"",
"st":"",
"z":"",
"ic":"",
"hd":"",
"latest":"",
"copyright":"",
"word":"长腿",
"s":"",
"se":"",
"tab":"",
"width":"",
"height":"",
"face":"",
"istype":"",
"qc":"",
"nc":"1",
"fr":"",
"expermode":"",
"force":"",
"pn":s, #页数
"rn":"30",
"gsm":"3c",
"1615535708375":"",
}
cookies = dict(cookies_are="working")
res =requests.get(url=url, headers=header, cookies=cookies, params=param)

res.encoding = 'utf-8'
text = res.json()

for i in text['data']:
if len(i) != 0:
r = requests.get(url=i['thumbURL'])
with open("./baiduimgs/" + str(n) + ".jpg", "wb") as code:
code.write(r.content)
print(str(n) + "下载完毕!")
n+=1
posted @ 2021-03-12 16:39  tevien  阅读(18)  评论(0)    收藏  举报