我发现你安装的是python3.9啊,我让你按的是 python3.8
nahongyan1997 发表于 2021-8-11 17:16
我发现你安装的是python3.9啊,我让你按的是 python3.8
安好了D:\win7我的文档-桌面-收藏夹\Desktop\JK5R{C_9M48GVW%5D17AKK){J.png
额,改好·了
本帖最后由 磊之茶 于 2021-8-11 19:43 编辑
nahongyan1997 发表于 2021-8-11 17:16
我发现你安装的是python3.9啊,我让你按的是 python3.8
Traceback (most recent call last):
File "D:/win7我的文档-桌面-收藏夹/Desktop/找来的爬虫.py", line 51, in <module>
result = j.loads(html)
File "C:\Users\Administrator.WOVLPG0YAW4QWRW\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\Administrator.WOVLPG0YAW4QWRW\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Administrator.WOVLPG0YAW4QWRW\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
仍是一言难尽
感谢分享!
!
磊之茶 发表于 2021-8-11 16:04
谢谢,不过
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)
这样改吧
竟然没鱼币,再试一次
临时号 发表于 2021-8-11 23:23
这样改吧
你这不就是把我的42句给拆开了吗
6666666666
nahongyan1997 发表于 2021-8-12 08:44
你这不就是把我的42句给拆开了吗
我把你的代码复制到IDLE中运行了,报错了后,我就开始改,不止是拆开,拆开只是因为我不习惯这样写
666
临时号 发表于 2021-8-12 14:22
我把你的代码复制到IDLE中运行了,报错了后,我就开始改,不止是拆开,拆开只是因为我不习惯这样写
的确没报错,但是我想问这跟我开始时有神马大差别。。。。。
访问是可以访问,但翻译貌似不行
nahongyan1997 发表于 2021-8-11 17:13
给你看看我这打印出来的东西,我什么都没动
感觉可能我用的代理IP被屏蔽了,response.read()显示啥都没有,不过你到底提交了神马,为啥我的显示提交有错误呢
来看看,我也是这个错误!
临时号 发表于 2021-8-11 23:23
这样改吧
虽然你的方法好,但是nohongyan1997回答我的问题并跟进了两天,于情于理也得有最佳答案,不过我会另开个感谢的悬赏帖感谢
不会。。。。
{:10_254:}
币来~
{:5_90:}