爬取百度翻译的结果:
但是目前获取不到右边的框里的那个东东.
感觉还是哪里有点问题,
这里能爬取列出的值
import requests
2 import json
3
4 def fanyi(keyword):
5 url = 'https://fanyi.baidu.com/sug'
6
7 # 定义请求参数
8 data = {
9 # 'from': 'en',
10 # 'to':'zh',
11 # 'query':keyword,
12 # 'transtype':'realtime',
13 # 'simple_means_flag':'3'
14 'kw': keyword
15 }
16
17 # 发送请求,抓取信息
18 res = requests.post(url,data=data)
19
20 # 解析结果并输出
21 str_json = res.text
22
23 myjson = json.loads(str_json)
24 # info = myjson['trans_result']['data'][0]['dst']
25 # print(myjson)
26 # info = myjson["from"]
27 # print(info)
28 for i in range (5):
29 info = myjson['data'][i]['v']
30 print(info)
31
32 if __name__=='__main__':
33 while True:
34 keyword = input('请输入翻译的单词:')
35 if keyword == 'q':
36 break
37 fanyi(keyword)