python爬虫百度翻译

import urllib.request
import urllib.parse

wrod=input('百度翻译')
url='https://fanyi.baidu.com/v2transapi?from=en&to=zh'
form_data={
    'query': wrod
}
headers={
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'
}
re_url=urllib.request.Request(url=url,headers=headers)

form_data=urllib.parse.urlencode(form_data).encode()
url_read=urllib.request.urlopen(re_url,data=form_data).read().decode()
print(url_read)

 

报错

{"errno":997,"errmsg":"未知错误","query":"baby","from":"en","to":"zh","error":997}

 

查看全部
weixin_48181189
溥仪没皇宫
2020/12/05 11:25
  • python
  • 点赞
  • 收藏
  • 回答
    私信

1个回复