Python crawl Baidu Translator returns: {' ERROR ': 997, ' from ': ' zh ', ' to ': ' en ', ' query question '

Source: Internet
Author: User

Workaround:

Modify the address for the mobile version of the URL: Http://fanyi.baidu.com/basetrans
User-agent also uses the mobile version of the

Test code:
# -*- coding: utf-8 -*-"""-------------------------------------------------   File Name:     requestsGet   Description :    爬取在线翻译数据s   Author :       神秘藏宝室   date:          2018-04-17-------------------------------------------------   Change Activity:                   2018-04-17:-------------------------------------------------"""import requestsurl = "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
return Result:
{"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":"你好"}]}

Python crawl Baidu Translator returns: {' ERROR ': 997, ' from ': ' zh ', ' to ': ' en ', ' query question '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.