<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### 高三網 goquery包github地址:https://github.com/PuerkitoBio/goquery 目標網站(高三網):http://www.gaosan.com/gaokao/85464.html 下面開始操作 老方法,cmd go get獲取包,復制他的示例代碼,安裝,顯然很成功 ![](https://img.kancloud.cn/72/c8/72c834f732b60c692651d6a130ee8add_1367x333.png) ![](https://img.kancloud.cn/c3/7a/c37ac8be3d213c1b103bffb9795304bf_1030x642.png) 現在開始學習使用他這包的方法,根據節點爬取自己需要的內容。這里爬取這表格 ![](https://img.kancloud.cn/bb/ca/bbca06c1ca9d9dc418dca24baee34cea_1829x799.png) 運行結果: ![](https://img.kancloud.cn/93/cf/93cf57ca6fdc0e7d06c2d92f8c5e3872_1531x420.png) Find()的用法,td:nth-child(1)第一個td的標簽,只有一個標簽只能這樣了 ``` package main import ( "fmt" "net/http" "github.com/PuerkitoBio/goquery" ) // 搞一個結構體 儲存json 數據 type List struct { Schoolname string `json:"schoolname"` Department string `json:"department"` Region string `json:"region"` Class string `json:"class"` } // 項目名稱 高三網 func Gaosan() { list := []List{} // 使用http包的get方法 發起請求html頁面 res, err := http.Get("http://www.gaosan.com/gaokao/85464.html") // 錯誤處理 if err != nil { fmt.Println(err) } // 結束時關閉 釋放資源 defer res.Body.Close() // 網頁狀態碼 if res.StatusCode != 200 { fmt.Println("請求超時!") } // 使用goquery包的方法加載html網頁 doc, err := goquery.NewDocumentFromReader(res.Body) if err != nil { fmt.Println(err) } // 根據節點 解析網頁 doc.Find("#data85464 table tr").Each(func(i int, s *goquery.Selection) { // 抓取節點 td標簽的 文字內容 // title := s.Find("td:nth-child(" + strconv.Itoa(1) + ")").Text() //fmt.Printf("內容 %d: %s\n", i, title) // 這樣輸出也可以 // fmt.Println(s.Text()) schoolname := s.Find("td:nth-child(1)").Text() department := s.Find("td:nth-child(2)").Text() region := s.Find("td:nth-child(3)").Text() class := s.Find("td:nth-child(4)").Text() list = append(list, List{ Schoolname: schoolname, Department: department, Region: region, Class: class, }) }) // 輸出 josn的結構體 fmt.Println(list) } func main() { Gaosan() } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看