Skip to content

Instantly share code, notes, and snippets.

@kazukgw
Created October 28, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazukgw/d5ba8814bbde7afe42e1 to your computer and use it in GitHub Desktop.
Save kazukgw/d5ba8814bbde7afe42e1 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io"
"net/http"
gq "github.com/PuerkitoBio/goquery"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/transform"
)
var URL = "http://www.kyounoryouri.jp/index.php?flow=recipe_fit_search_result&type=all&keyword=大根&exclude_keyword="
func main() {
resp, err := http.Get(URL)
if err != nil {
panic(err.Error())
}
decoder := NewDecoder(resp.Body)
doc, _ := gq.NewDocumentFromReader(decoder)
doc.Find(".box_hub_recipe01").Each(func(_ int, s *gq.Selection) {
fmt.Println(s.Find(".recipeTitle a").Text())
fmt.Println(s.Find(".recipeTitle a").Attr("href"))
})
}
func NewDecoder(reader io.Reader) *transform.Reader {
return transform.NewReader(reader, japanese.ShiftJIS.NewDecoder())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment