• 看源码,弄清楚各个结构体


    https://github.com/PuerkitoBio/goquery#api


    package main

    import (
    "fmt"
    "log"
    "net/http"

    "github.com/PuerkitoBio/goquery"
    )
    /*
    <ul class="app-news-detail__meta"><li class="app-news-detail__meta-item">2018-08-30 11:54:44</li><!----></ul>
    document.getElementsByClassName("app-news-detail__meta-item").length = 1

    */
    func ExampleScrape() {
    // Request the HTML page.
    res, err := http.Get("http://cn.sonhoo.com/wukong/a182281")
    if err != nil {
    log.Fatal(err)
    }
    defer res.Body.Close()
    if res.StatusCode != 200 {
    log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
    }

    // Load the HTML document
    doc, err := goquery.NewDocumentFromReader(res.Body)
    if err != nil {
    log.Fatal(err)
    }

    // Find the review items
    doc.Find(".app-news-detail__meta-item").Each(func(i int, s *goquery.Selection) {
    // For each item found, get the band and title
    band := s.Find("a").Text()
    title := s.Find("i").Text()
    fmt.Printf("Review %d: %s - %s ", i, band, title)
    // 目标值
    ii := s.Text()
    fmt.Println(ii)
    })
    // https://github.com/PuerkitoBio/goquery#api
    // 看源码,弄清楚各个结构体
    i := doc.Find(".app-news-detail__meta-item")
    for _, v := range i.Nodes {
    fmt.Println(v.FirstChild.Data)
    break
    }
    }

    func main() {
    ExampleScrape()
    }



  • 相关阅读:
    InChatter系统之服务器开发(一)
    InChatter系统开源聊天模块前奏曲
    System.Lazy<T>延迟加载
    系统的层级架构
    Android网络通信库Volley简介(转)
    switch case 忘记 break
    switch case 忘记 break
    C# Lock 解读
    JSON资料整理(转载)
    [Leetcode]253. 会议室 II(数组/堆)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9566416.html
Copyright © 2020-2023  润新知