#解決辦法: 修改url爲手機版的地址:http://fanyi.baidu.com/basetrans User-Agent也用手機版的
#測試代碼:post
# -*- coding: utf-8 -*- """ ------------------------------------------------- File Name: requestsGet Description : 爬取在線翻譯數據s Author : 神祕藏寶室 date: 2018-04-17 ------------------------------------------------- Change Activity: 2018-04-17: ------------------------------------------------- """ import requests url = "http://fanyi.baidu.com/basetrans" data = { "query":"你好世界", "from":"zh", "to":"en", } headers = { "User-Agent":"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Mobile Safari/537.36", } response = requests.post(url,data = data,headers = headers) # print response.request.url #請求地址 # print response.url #響應地址 # print response.request.headers #請求頭 # print response.headers #響應頭 print response.content.decode('unicode-escape') #顯示出來unicode的中文 # print response.text
#返回結果:測試
{"errno":0,"from":"zh","to":"en","trans":[{"dst":"Hello world","prefixWrap":0,"src":"你好世界","relation":[],"result":[[0,"Hello world",["0|12"],[],["0|12"],["0|11"]]]}],"dict":[],"keywords":[{"means":["hello","hi","How do you do!"],"word":"你好"}]}