首先通过抓包工具发现,该案例是一个post请求,响应数据为json类型
实现如下:
import requests
import json
URL = "https://fanyi.baidu.com/sug"
#UA伪装
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67'
}
#参数
data = {
'kw': 'big'
}
#发起请求
response = requests.post(url = URL,headers = header,params=data)
#获取响应数据
page_ = response.json()
#持久化存储
fp = open('./big.json','w',encoding='utf-8')
json.dump(page_,fp,ensure_ascii = False) #ensuer_ascii:保留非ascii字符,不被转义