如何用goquery获得leetcode排名

时间:2017-08-18 08:29:10

标签: goquery

我想得到我的leetcode排名,但我对html和JavaScript了解一点点。经过大量的尝试,我得到了这个输出。

   aQuaYi的排名是排名: {[{pc.ranking}]}

来源是

protected static class MyTwinCallback implements IotHubEventCallback
{
    public void execute(IotHubStatusCode status, Object context)
    {
        System.out.println("IoT Hub responded to device twin operation with status " + status.name());
    }
}

请帮我完成此代码,非常感谢。

1 个答案:

答案 0 :(得分:0)

func getRanking(username string) string {
    URL := fmt.Sprintf("https://leetcode.com/%s/", username)
    fmt.Println(URL)

    data := getRaw(URL) // or your way to get raw html page down
    str := string(data)
    i := strings.Index(str, "ng-init")
    j := i + strings.Index(str[i:], "ng-cloak")
    str = str[i:j]

    i = strings.Index(str, "(")
    j = strings.Index(str, ")")
    str = str[i:j]

    strs := strings.Split(str, ",")
    ans := strs[5]
    i = strings.Index(ans, "'")
    j = 2 + strings.Index(ans[2:], "'")

    return ans[i+1 : j]
}