携带post参数的爬虫
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
import requests import json
if __name__ == "__main__": post_url = 'https://fanyi.baidu.com/sug' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36' } print('******************************************************') word = input('请输入您要翻译的文本: ') data = { 'kw': word } response = requests.post(url=post_url, data=data, headers=headers) dic_obj = response.json() print(dic_obj) fileName = word + '.json' fp = open(fileName, 'w', encoding='utf-8') json.dump(dic_obj, fp=fp, ensure_ascii=False)
print('******************************************************')
|
Tips:
Please indicate the source and original author when reprinting or quoting this article.