diff --git a/README.md b/README.md index ef2fb8a..77b99ad 100644 --- a/README.md +++ b/README.md @@ -36,21 +36,21 @@ $ goscholar -h ```go // create Query and generate URL -q := Query{Keywords:"deep learning", Author:"y bengio"} -url = q.SearchUrl() +q := Query{Keywords:"nature 2015", Author:"y bengio", Title:"Deep learning"} +url := q.SearchUrl() // fetch document sending the request to the URL -doc, err := goscholar.Fetch(url) +doc, err := Fetch(url) if err != nil { - log.Error(err) + log.Error(err) return } // parse articles -ch := make(chan *goscholar.Article, 10) -go goscholar.ParseDocument(ch, doc) - +ch := make(chan *Article, 10) +go ParseDocument(ch, doc) for a := range ch { + fmt.Println("---") fmt.Println(a) } ``` diff --git a/article.go b/article.go index d8d671c..848eeab 100644 --- a/article.go +++ b/article.go @@ -10,26 +10,26 @@ import ( // Article stores the parsed results from Google Scholar. type Article struct { - Title *Title - Year string - ClusterId string - NumCite string - NumVer string - InfoId string - Link *Link + Title *Title `json:"title"` + Year string `json:"year"` + ClusterId string `json:"cluster_id"` + NumCite string `json:"num_cite"` + NumVer string `json:"num_ver"` + InfoId string `json:"info_id"` + Link *Link `json:"link"` } // Title is an attribute of Article. type Title struct { - Name string - Url string + Name string `json:"name"` + Url string `json:"url"` } // Link is an attribute of Article type Link struct { - Name string - Url string - Format string + Name string `json:"name"` + Url string `json:"url"` + Format string `json:"format"` } // NewArticle creates an Article in which all entry is blank. diff --git a/article_test.go b/article_test.go index 78074b4..4a02c1f 100644 --- a/article_test.go +++ b/article_test.go @@ -91,7 +91,7 @@ func ExampleString() { func ExampleJson() { fmt.Println(article.Json()) // Output: - // {"Title":{"Name":"Deep learning via Hessian-free optimization","Url":"http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf"},"Year":"2010","ClusterId":"15502119379559163003","NumCite":"260","NumVer":"9","InfoId":"e6RSJHGXItcJ","Link":{"Name":"wustl.edu","Url":"http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf","Format":"PDF"}} + // {"title":{"name":"Deep learning via Hessian-free optimization","url":"http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf"},"year":"2010","cluster_id":"15502119379559163003","num_cite":"260","num_ver":"9","info_id":"e6RSJHGXItcJ","link":{"name":"wustl.edu","url":"http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf","format":"PDF"}} } func TestIsValid(t *testing.T) { diff --git a/parse_test.go b/parse_test.go index 4a53906..fb4e991 100644 --- a/parse_test.go +++ b/parse_test.go @@ -75,38 +75,24 @@ func checkWithFirst(doc *goquery.Document, aExpected *Article) (err error) { } func Example() { - ch := make(chan *Article, 10) - + // create Query and generate URL q := Query{Keywords:"nature 2015", Author:"y bengio", Title:"Deep learning"} url := q.SearchUrl() + // fetch document sending the request to the URL doc, err := Fetch(url) if err != nil { log.Error(err) return } + // parse articles + ch := make(chan *Article, 10) go ParseDocument(ch, doc) - a := <- ch - fmt.Println(a) - // Output: - /*[Title] - Name: Deep learning - Url: http://www.nature.com/nature/journal/v521/n7553/abs/nature14539.html -[Year] - 2015 -[ClusterId] - 5362332738201102290 -[NumCite] - 390 -[NumVer] - 7 -[InfoId] - 0qfs6zbVakoJ -[Link] - Name: psu.edu - Url: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.436.894&rep=rep1&type=pdf - Format: PDF*/ + for a := range ch { + fmt.Println("---") + fmt.Println(a) + } } func TestParseSelection(t *testing.T) {