from urllib.request import *
from urllib.parse import urlencode
import json as j
from pprint import pprint
from io import BytesIO
header = {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,ko;q=0.8,ga;q=0.7",
"Connection": "keep-alive",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
"Host": "fanyi.sogou.com",
"Origin": "https://fanyi.sogou.com",
"Referer": "https://fanyi.sogou.com/text",
"Content-Type": "application/json;charset=UTF-8",
"Cookie": "ABTEST=0|1628641545|v17; IPLOC=CN2102; SUID=1C377177EF53A00A0000000061131909; SNUID=AF83C5C3B3B67D8E1C7E84C5B48B72CD; FUV=7780e23e4a0de1b60632bc7d414ef4d0; SGINPUT_UPSCREEN=1628641551176; SUV=1628641551193"
}
data = {
'client': "pc",
'exchange':'false',
'fr':"browser_pc",
'from':"auto",
'needQc':'1',
's':"d78cdd5a1a76770c398ca51493d3a2c0",
'text':"I like FishC.com",
'to':"zh-CHS",
'uuid':"12681881-4857-4a6a-be0e-8c7bd28a73d3"
}
data = j.dumps(data).encode('utf-8')
header["Content-Length"] = len(data)
ps=ProxyHandler({'http':'223.244.179.85:3256'})
opener = build_opener(ps)
Req = Request(r'https://fanyi.sogou.com/api/transpc/text/result',data,header)
response = opener.open(Req)
fileobj=BytesIO(response.read())
html = fileobj.read()
result = j.loads(html.decode())
print(result)
这样改吧 |