expect result:
[
{
"contentData":"1 \u0e21\u0e01\u0e23\u0e32\u0e04\u0e21 ",
"historyData":"
\u0e27\u0e31\u0e19\u0e02\u0e36\u0e49\u0e19\u0e1b\u0e35\u0e43\u0e2b\u0e21\u0e48\u00a0
\u0e27\u0e31\u0e19\u0e2b\u0e22\u0e38\u0e14\u0e23\u0e32\u0e0a\u0e01\u0e32\u0e23",
"id":1
},
{"contentData":"\u0e27\u0e31\u0e19\u0e40\u0e2a\u0e32\u0e23\u0e4c\u0e17\u0e35\u0e48
2
\u0e02\u0e2d\u0e07\u0e40\u0e14\u0e37\u0e2d\u0e19\u0e21\u0e01\u0e23\u0e32\u0e04\u0e21
",
"historyData":"
\u0e27\u0e31\u0e19\u0e40\u0e14\u0e47\u0e01\u0e41\u0e2b\u0e48\u0e07\u0e0a\u0e32\u0e15\u0e34","id":2}
]
เมื่อ วันพฤหัสบดีที่ 10 มกราคม ค.ศ. 2019 1 นาฬิกา 30 นาที 19 วินาที UTC+7,
[email protected] เขียนว่า:
>
> package main
>
> import (
> "log"
> "net/http"
> "time"
>
> "github.com/PuerkitoBio/goquery"
> "gopkg.in/mgo.v2"
> //"gopkg.in/mgo.v2"
> )
>
> type Data struct {
> Name string `json:"name" bson:"name"`
> Away string `json:"away" bson:"away"`
> Pop int `json:"pop" bson:"pop"`
> CreatedAt time.Time `bson:"createdAt"`
> }
>
> func ExampleScrape() {
> // Request the HTML page.
> session, err := mgo.Dial("mongodb://127.0.0.1:27017")
> res, err := http.Get("
> https://www.edtguide.com/place/%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B8%9E%E0%B8%A2%E0%B8%B2%E0%B8%9A%E0%B8%B2%E0%B8%A5/%E0%B8%AA%E0%B8%A1%E0%B8%B8%E0%B8%97%E0%B8%A3%E0%B8%9B%E0%B8%A3%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3/view/P0
> ")
> 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(".archive-list article ").Each(func(i int, s
> *goquery.Selection) {
> // For each item found, get the band and title
> band := s.Find("p").Text()
>
> title := s.Find("h2").Text()
> log.Printf("Review %d: %s - %s\n", i, band, title)
> session.SetMode(mgo.Monotonic, true)
> d := session.DB("api").C("api")
>
> doc := Data{
> Name: title,
> Away: band,
> Pop: 1000,
> }
>
> err = d.Insert(doc)
>
> if err != nil {
> panic(err)
> }
>
> })
>
> }
>
> func main() {
> ExampleScrape()
>
> }
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.