The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
rita413413

gocolly colly 爬取单页面站点吗?

  •  
  •   rita413413 · Aug 5, 2021 · 1893 views
    This topic created in 1748 days ago, the information mentioned may be changed or developed.
    1 replies    2021-08-05 17:54:38 +08:00
    py88pQ2hZ7PJw0v4
        1
    py88pQ2hZ7PJw0v4  
       Aug 5, 2021
    请使用 chromedp

    ```go
    var html string
    err := chromedp.Run(ctx,
    chromedp.Tasks{
    network.Enable(),
    // 打开导航
    // 等待元素加载完成
    network.SetExtraHTTPHeaders(network.Headers{"isInternalServer": "1"}), // 这个设置 header
    setCookies( // 这里设置 cookie
    "access_token", "token",
    ),
    chromedp.Navigate("你需要爬的站点"),
    chromedp.WaitVisible("body", chromedp.ByQuery), // 等待 body 加载完毕
    chromedp.Sleep(5 * time.Second), // 等待 api 调用完毕

    // 输出
    chromedp.OuterHTML("html", &html),
    },
    )
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1110 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 22:57 · PVG 06:57 · LAX 15:57 · JFK 18:57
    ♥ Do have faith in what you're doing.