请问用Python和go请求同一个url返回的内容为什么不一样

JonBuild · · 1071 次点击 · 开始浏览    置顶

最近在学习go,就用go写了一个简单的爬虫,解析结果时发现返回结果无法反序列化,仔细核对发现返回的结果跟python的不一样,go的结果是`"data":[{"info":[{"p1688":{"name":"珠宝品,"unit":"元/吨","value":"塑料行情"}}]`,python的结果是`"data":[{"info":[{"p1688":{"name":"珠宝品牌","unit":"元/吨","value":"塑料行情"}}],` 在“珠宝品”那三个字后面少了一个双引号,后面的内容也不一致。请问大家知道这是什么问题么。 具体代码如下 ```go package main import ( "fmt" "io/ioutil" "net/http" "time" ) func main() { code := "JO_112033" page := 1 timeStamp := time.Now().UnixMilli() url := "https://api.jijinhao.com/history/quotejs.htm?codes=%s&style=3&currentPage=%d&pageSize=3&_=%d" url = fmt.Sprintf(url, code, page, timeStamp) fmt.Println(url) resp, _ := http.Get(url) body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body)) } ``` go解析结果如下 ``` var quot_str = [{"totalPage":"402","totalCount":"1206","data":[{"info":[{"p1688":{"name":"珠宝品,"unit":"元/吨","value":"塑料行情"}}],"quote":{"q68":"PPlibaojia","q124":"JO_112033","q67":"PP粒1":"8318.3300","q3":"8318.3300","q4":"8318.3300","q2":"8318.3300","q60":"1.0000","q62":"0.0000","qhistoryStyle":"3.0000","q128":"0.0000","q80":"-0.3793","q193":"1.0000","q70":"-31.6699","q63":"8318.3300","q59":"2022-10-18 00:00:00"}},{"info":[{"p1688":{"name":"珠宝品牌","unit":"元/吨"e":"塑料行情"}}],"quote":{"q68":"PPlibaojia","q124":"JO_112033","q67":"PP粒报价","q1":"8350.000:"8350.0000","q4":"8350.0000","q2":"8350.0000","q60":"1.0000","q62":"0.0000","qhistoryStyle":"3.0000","q128":"0.0000","q80":"0.0000","q193":"1.0000","q70":"0.0000","q63":"8350.0000","q59":"2022-10-17 00:00:00"}},{"info":[{"p1688":{"name":"珠宝品牌","unit":"元/吨","value":"塑料行情"}}]"q68":"PPlibaojia","q124":"JO_112033","q67":"PP粒报价","q1":"8391.6700","q3":"8391.6700","q4":"1.6700","q2":"8391.6700","q60":"1.0000","q62":"0.0000","qhistoryStyle":"3.0000","q128":"0.0000","q80":"-0.4940","q193":"1.0000","q70":"-41.6602","q63":"8391.6700","q59":"2022-10-14 00:00:00"}}]}] ``` Python代码 ``` from requests_html import HTMLSession url = "https://api.jijinhao.com/history/quotejs.htm?codes=JO_112033&style=3&currentPage=1&pageSize=3&_=1666071223908" res = HTMLSession().get(url) print(res.text) ``` Python返回结果如下 ``` var quot_str = [{"totalPage":"402","totalCount":"1206","data":[{"info":[{"p1688":{"name":"珠宝品牌","unit":"元/吨","value":"塑料行情"}}],"quote":{"q68":"PPlibaojia","q124":"JO_112033","q67":"PP粒报价","q1":"8318.3300","q3":"8318.3300","q4":"8318.3300","q2":"8318.3300","q60":"1.0000","q62":"0.0000","qhistoryStyle":"3.0000","q128":"0.0000","q80":"-0.3793","q193":"1.0000","q70":"-31.6699","q63":"8318.3300","q59":"2022-10-18 00:00:00"}},{"info":[{"p1688":{"name":"珠宝品牌","unit":"元/吨","value":"塑料行情"}}],"quote":{"q68":"PPlibaojia","q124":"JO_112033","q67":"PP粒报价","q1":"8350.0000","q3":"8350.0000","q4":"8350.0000","q2":"8350.0000","q60":"1.0000","q62":"0.0000","qhistoryStyle":"3.0000","q128":"0.0000","q80":"0.0000","q193":"1.0000","q70":"0.0000","q63":"8350.0000","q59":"2022-10-17 00:00:00"}},{"info":[{"p1688":{"name":"珠宝品牌","unit":"元/吨","value":"塑料行情"}}],"quote":{"q68":"PPlibaojia","q124":"JO_112033","q67":"PP粒报价","q1":"8391.6700","q3":"8391.6700","q4":"8391.6700","q2":"8391.6700","q60":"1.0000","q62":"0.0000","qhistoryStyle":"3.0000","q128":"0.0000","q80":"-0.4940","q193":"1.0000","q70":"-41.6602","q63":"8391.6700","q59":"2022-10-14 00:00:00"}}]}] ```

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1071 次点击  ∙  1 赞  
加入收藏 微博
8 回复  |  直到 2022-10-20 12:28:07
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传