python爬虫学习——requests百度翻译
作者:互联网
import requests
import json
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
post_url = 'https://fanyi.baidu.com/sug'
word = input('Enter a word')
data = {
'kw':word
}
response = requests.post(url=post_url, data=data, headers=header)
dic_obj = response.json()
fileName = word + '.json'
fp = open(fileName, 'w', encoding='utf-8')
json.dump(dic_obj, fp=fp, ensure_ascii=False)
print('爬取结束!!!')
标签:fp,word,python,爬虫,url,json,requests,data,post 来源: https://www.cnblogs.com/bwin/p/16495816.html