python爬虫入门教程——爬取360翻译
程序员文章站
2022-05-04 12:07:24
...
python爬虫入门教程之爬取360翻译,可以英汉互译 ,简单入门,绝对易学,使用requests模块爬虫。
'''
Python爬取360翻译
'''
import requests
import json
query = input('请输入你要翻译的内容:')
url = 'http://fanyi.so.com/index/search'
query_string = {"query": query,"eng": "0","validate": ""}
headers = {"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"}
response = requests.post(url=url,data=query_string,headers=headers)
response.encoding = 'utf-8'
dict_ret = json.loads(response.text)
print(dict_ret['data']['fanyi'])