请问各位大佬, 服务器返回的数据为GB18030的, 打印请求结果如下, 中文变成乱码的问题可以解决吗? JavaScript
{ “StatusCode”: 200, “Header”: { “Cache-Control”: [ “no-cache” ], “Connection”: [ “Keep-Alive” ], “Content-Type”: [ “application/javascript; charset=GB18030” ] }, “Cookies”: [], “Body”: “var hq_str_gb_$dji=“���˹,34988.8398,1.22,2022-02-16 06:01:05,422.6700,34686.1914,35047.7891,34686.1914,36952.6484,30547.5293,305666649,370199515,0,0.00,–,0.00,0.00,0.00,0.00,0,0,0.0000,0.00,0.0000,Feb 15 05:00PM EST,34566.1719,0,1,2022”;\nvar hq_str_gb_ixic=“��˹��,14139.7573,2.53,2022-02-16 06:30:00,348.8385,13997.1793,14142.4927,13976.2912,16212.2285,12397.0537,3927636514,3859625497,0,0.00,–,0.00,0.00,0.00,0.00,0,0,0.0000,0.00,0.00,Feb 15 05:16PM EST,13790.9188,0,1,2022,0.0000,0.0000,0.0000,0.0000,0.0000”;\nvar hq_str_gb_$inx=“���500ָ��,4471.0698,1.58,2022-02-16 06:01:05,69.4000,4429.2798,4472.7700,4429.2798,4818.6201,3723.3401,2322886082,2633272939,0,0.00,–,0.00,0.00,0.00,0.00,0,0,0.0000,0.00,0.0000,Feb 15 05:00PM EST,4401.6699,0,1,2022”;\nvar hq_str_hf_GC=“1854.430,1854.000,1854.200,1856.500,1851.800,13:20:36,1856.200,1855.500,434039.000,12,14,2022-02-16,ŦԼ��,10348”;\nvar hq_str_hf_CL=“92.017,92.050,92.060,92.560,91.630,13:20:41,92.070,92.210,156766.000,6,1,2022-02-16,WTIŦԼԭ��,19549”;\nvar hq_str_DINIW=“13:20:37,96.0232,96.0232,95.9851,1042,95.9867,96.0705,95.9663,96.0232,��Ԫָ��,2022-02-16”;\nvar hq_str_s_sh000001=“��ָ֤��,3464.4051,18.3166,0.53,1937911,22953814”;\nvar hq_str_rt_hkHSI=“HSI,���ָ��,24618.300,24355.711,24728.930,24548.050,24632.311,276.600,1.140,0.000,0.000,59978587.742,5054267122,0.000,0.000,31183.359,22665.250,2022/02/16,13:20:43,”;\nvar hq_str_b_NKY=“�վ�25ָ��,27468.5000,603.31,2.25,2/15/2022,2022-02-15,2022-02-16,13:18:00,27405.0000,26865.1900,27477.5000,27345.0000,0”;\n” }
发明者量化-小小梦 调用HttpQuery函数发送Http请求的时候指定一下请求头中的字符集设置试下。"application/javascript; charset=xxx" 设置成utf-8之类的。
发明者量化-小小梦 不客气,感谢您提出的问题。
18599999999 确实可以了, 点赞
发明者量化-小小梦 测试检查了,针对您反应的这个问题,我们升级了一下托管者。 ``` function main() { var ret = HttpQuery( "https://hq.sinajs.cn/rn=1644985273291&list=gb_$dji,gb_ixic,gb_$inx,hf_GC,hf_CL,DINIW,s_sh000001,rt_hkHSI,b_NKY", {method: "GET",charset:"GB18030"}, null, "Referer: https://stock.finance.sina.com.cn/usstock/quotes/.IXIC.html", true ) Log(ret.Body) } ``` 您使用最新的托管者,然后使用这个代码调试,就正常显示中文字符了。
18599999999 站长大佬. 这个问题能通过代码解决吗? 或者短时间能解决吗
18599999999 代码请见https://www.fmz.com/strategy/345557
发明者量化-小小梦 需要看下你的代码具体怎么写的,HttpQuery 和上下文。
18599999999 我尝试在headers中添加了"Content-Type": "application/javascript; charset=utf-8", 还是不行(不知道这样对不对). 估计服务器就只能返回这种字符集. 而且爬取的财经数据, 改请求头也可能会被识别. 不知道有没有其他办法. 这个功能我在浏览器控制台的环境是不会出现乱码的, 不知道为什么