python爬虫入门教程之爬取360翻译,

使用requests模块和json模块,通过分析360翻译的网络请求,通过Python实现将其结果爬取。

'''
Python爬取360翻译
'''
import requests
import json
query = input('请输入你要翻译的内容:')
url = 'http://fanyi.so/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'])

 

更多推荐

python爬虫入门教程——爬取360翻译