最近在学习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¤tPage=%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¤tPage=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"}}]}]
```
有疑问加站长微信联系(非本文作者)