鱼C论坛

 找回密码
 立即注册
查看: 1636|回复: 1

[作品展示] 爬取翻译结果

[复制链接]
发表于 2020-5-12 09:46:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
360翻译
  1. import requests
  2. import json
  3. def req(mes):
  4.     data = {
  5.     'eng': 0,
  6.     'validate': '',
  7.     'ignore_trans': 0,
  8.     'query': mes,
  9.     }
  10.     headers = {
  11.         'Accept': 'application/json, text/plain, */*',
  12.         'Accept-Encoding': 'gzip,deflate',
  13.         'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  14.         'Connection': 'keep-alive',
  15.         'Content-Length': '0',
  16.         'Cookie': 'Q_UDID=88eb521c-7152-f556-0b90-e6c89ba884de; __guid=144965027.914035386670474100.1589183201604.5356; count=4',
  17.         'Host': 'fanyi.so.com',
  18.         'Origin': 'http://fanyi.so.com',
  19.         'pro': 'fanyi',
  20.         'Referer': 'http://fanyi.so.com/',
  21.         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.14 Safari/537.36 Edg/83.0.478.13'
  22.     }
  23.     url = "http://fanyi.so.com/index/search?eng=0&validate=&ignore_trans=0&query=%E4%BD%A0%E5%A5%BD"
  24.     respoon = requests.post(url=url, headers=headers,
  25.                             data=data).content.decode("utf-8")
  26.     print(json.loads(respoon)['data']['fanyi'])
  27. if __name__ == "__main__":
  28.     while True:
  29.         req(input("需要翻译的句子:"))
复制代码

headers只写ueser agent和pro 就行,但是我多写也不错
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-5-12 11:37:07 | 显示全部楼层
沙发
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-19 07:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表