<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          scrapeWeb 爬蟲

          聯(lián)合創(chuàng)作 · 2023-09-29 13:28

          scrape 是一個簡單高級的 Web 爬蟲庫,使用 Go 語言開發(fā)。

          示例代碼:

          package main
          
          import (
              "fmt"
              "net/http"
          
              "github.com/yhat/scrape"
              "golang.org/x/net/html"
              "golang.org/x/net/html/atom"
          )
          
          func main() {
              // request and parse the front page
              resp, err := http.Get("https://news.ycombinator.com/")
              if err != nil {
                  panic(err)
              }
              root, err := html.Parse(resp.Body)
              if err != nil {
                  panic(err)
              }
          
              // define a matcher
              matcher := func(n *html.Node) bool {
                  // must check for nil values
                  if n.DataAtom == atom.A && n.Parent != nil && n.Parent.Parent != nil {
                      return scrape.Attr(n.Parent.Parent, "class") == "athing"
                  }
                  return false
              }
              // grab all articles and print them
              articles := scrape.FindAll(root, matcher)
              for i, article := range articles {
                  fmt.Printf("%2d %s (%s)\n", i, scrape.Text(article), scrape.Attr(article, "href"))
              }
          }
          瀏覽 13
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  啪啪啪湿佬网站 | 中文在线字 | 激情五月,五月婷婷 | 日产精品一区二区乱码视频 | 无码高清在线播放 |