我在为我的 graphql 解析器创建有效负载时遇到问题。如何重写它以返回完成的数组?
我被困在里面,无法返回数据。c.OnHTML("article", func(e *colly.HTMLElement) {}
type Article struct {
Title string `bson:"title"`
Source string `bson:"source"`
Url string `bson:"url"`
Timestamp string `bson:"timestamp"`
}
func (r *RootResolver) News() ([]models.Article, error) {
c := colly.NewCollector(
colly.MaxDepth(2),
colly.Async(),
)
c.Limit(&colly.LimitRule{Parallelism: 10})
articles := []models.Article{}
c.OnHTML("article", func(e *colly.HTMLElement) {
articleModel := []models.Article{
{
Title: e.ChildText("h3 a"),
Source: e.ChildText("a[data-n-tid]"),
Timestamp: e.ChildAttr("div:last-child time", "datetime"),
Url: e.ChildAttr("a[href]", "href"),
},
}
fmt.Println(articleModel)
})
c.Visit(SOMEURLHERE)
c.Wait()
return articles, nil
}
人到中年有点甜
相关分类