Created
October 28, 2015 14:10
-
-
Save kazukgw/d5ba8814bbde7afe42e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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