import json
import requests
if __name__ == '__main__':
# 1.指定url地址
url = 'https://fanyi.baidu.com/sug'
# 2.指定动态搜取数据
word=input("enter a word:")
data={
'kw':word
}
# 3.使用UA伪装
headers = {
'Usr-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4878.0 Safari/537.36'
}
# 4.请求发送数据
response = requests.post(url=url, data=data, headers=headers)
# 5.响应数据
dic_obj = response.json()
# 6.持久化存储
fileName = word + '.json'
fp = open(fileName, 'w', encoding='utf-8')
json.dump(dic_obj, fp=fp, ensure_ascii=False)
print("爬取数据成功!!!")