[Python] 纯文本查看 复制代码 import os
import requests
from urllib.parse import quote
kw = quote('表情包')#把文字编码成urlencode的
pn = 30 # 一页等于30 两页等于60 以此类推
url = f'https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&word={kw}&pn={pn}&rn=30' # rn是一页显示多少个的意思
headers = {
'Referer': 'https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&fm=result&pos=history&word=%E8%A1%A8%E6%83%85%E5%8C%85',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0',
'Host': 'image.baidu.com'}
req = requests.get(url=url, headers=headers).json()
# print()
a = 1
for i in req['data']:
try:
print(i['thumbURL'])
with open(f'{a}.{os.path.splitext(i["thumbURL"])[-1]}', 'wb') as f: # 这里我随便给图片数字的标题 你们喜欢的话可以随便弄无所谓的 os.path.splitext(i["thumbURL"])[-1] 获取后缀名
f.write(requests.get(i['thumbURL']).content)
f.close()
a = a + 1
except Exception as e:
print(e)
也没啥技术含量 适合新手 |