andeya / pholcus

Pholcus is a distributed high-concurrency crawler software written in pure golang
Apache License 2.0
7.58k stars 1.7k forks source link

请问这个框架支持json请求吗 #111

Closed superpluss closed 4 years ago

superpluss commented 5 years ago

如题!有些页面需要爬接口是json请求的,但是我没找到怎样以json请求的

headers.Set("Content-Type", "application/json")
ctx.AddQueue(&request.Request{
    Url:          "",
    Rule:         "登录",
    Method:       http.MethodPost,
    EnableCookie: true,
    PostData:     `{"input":{"Username":"18989849679","Password":"12345678"}}`,
    Header:       headers,
        })

这样设置无效,是不是不支持

zzdts commented 5 years ago

将json中的引号转义即可:

ParseFunc: func(ctx *Context) {
    ctx.AddQueue(&request.Request{
        Url:    WebHostPost,
        Rule:   "登录后",
        Method: "POST",
        // PostData: "username=123456@qq.com&password=123456",
        PostData: "{\"uid\":\"rain\",\"key\":\"123456\",\"cmd\":\"login\"}",
        })
    },
andeya commented 5 years ago

和转义无关,两种写法等价,都支持。