原来python也能对实现简单的搜狗翻译

原来python也能对实现简单的搜狗翻译

import hashlib
import requests
import  re
if __name__ == '__main__':
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42',
        "x-requested-with": "XMLHttpRequest",
        "origin": "https://fanyi.baidu.com",
        "referer": "https://fanyi.baidu.com/?aldtype=16047",
        "Cookie":"ssuid=7578450800; IPLOC=CN3100; SUID=F032E28B1639960A000000006232CC75; SUV=1651048972958935; SMYUV=1654738753827713; ABTEST=7|1663744120|v17; SNUID=1824051C2520CF0CB8634BB5262C535A; wuid=1663744120080; FQV=600dbc0b73aa939b0ef6f5541d5e890c; translate.sess=9e2ec77e-1da9-4f86-9af3-dd742a75c4f5; SGINPUT_UPSCREEN=1663744120480"
    }
    text = "hello world"
    url2=f"https://fanyi.sogou.com/text?keyword={text}&transfrom=auto&transto=zh-CHS&model=general"

    # content = requests.post(url2, headers=headers, data=data).content.decode()
    content = requests.get(url2, headers=headers).content.decode()
    uuid = re.findall(r'<meta name="reqinfo" content="uuid:(.*?),', content)[0]
    url = "https://fanyi.sogou.com/api/transpc/text/result"

    t = f"autozh-CHS{text}109984457"
    tt = hashlib.md5(t.encode()).hexdigest()
    data = {"from": "auto", "to": "zh-CHS", "text": text, "client": "pc", "fr": "browser_pc", "needQc": 1,
            "s": tt, "uuid": uuid, "exchange": False}
    print(data)
    content = requests.post(url, headers=headers, data=data).content.decode()
    print(content)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值