我目前正在尝试从 RottenTomatoes 获取搜索列表以进行一些研究。我goquery
以一种简单的方式集成了不同的站点。但烂番茄的情况就不一样了。即使我尝试了不同的查询方式,我也无法获得搜索列表。
测试网址:https://www.rottentomatoes.com/search/?search=test
我想得到的文字:Testament
doc.Text()
输出: https://pastebin.com/SsWHYXTH
这是我所做的:
func ParseSearchMovies(doc *goquery.Document) *models.SearchResponse {
result := new(models.SearchResponse)
finder0 := doc.Find("section > section > ul")
finder1 := doc.Find("section.movieSection > ul")
finder2 := doc.Find("section.movieSection > ul > li")
finder3 := doc.Find("movieSection")
finder4 := doc.Find("section.movieSection")
finder5 := doc.Find("section.movieSection ul.results_ul")
finder6 := doc.Find("div.Search.Results li.bottom_divider.clearfix")
finder7 := doc.Find("div.search-results-root span.bold")
finder8 := doc.Find("div.search-results-root #details")
finder9 := doc.Find("div.search-results-root li.bottom_divider.clearfix")
finder10 := doc.Find("#movieSection > ul > li:nth-child(1)")
finder11 := doc.Find("#movieSection > ul")
finder12 := doc.Find("#movieSection > ul .bottom_divider.clearfix")
finder13 := doc.Find("#movieSection > ul > li")
finder14 := doc.Find("section.Search.Results .movieSection")
finder15 := doc.Find("#search-results-root section")
finder16 := doc.Find("#search-results-root .section")
finder17 := doc.Find("#search-results-root .section .section")
finder18 := doc.Find("#search-results-root > section > section")
finder19 := doc.Find("#search-results-root > section .section")
//From hlscalon's answer
finder20 := doc.Find("#movieSection > .results_ul > li > div.details")
finder21 := doc.Find("#movieSection > .results_ul > li")
finder22 := doc.Find("#movieSection > .results_ul")
finder23 := doc.Find("#movieSection")
fmt.Printf("%d", len(finder0.Nodes))
fmt.Printf("%d", len(finder1.Nodes))
fmt.Printf("%d", len(finder2.Nodes))
fmt.Printf("%d", len(finder3.Nodes))
fmt.Printf("%d", len(finder4.Nodes))
fmt.Printf("%d", len(finder5.Nodes))
fmt.Printf("%d", len(finder6.Nodes))
fmt.Printf("%d", len(finder7.Nodes))
fmt.Printf("%d", len(finder8.Nodes))
fmt.Printf("%d", len(finder9.Nodes))
fmt.Printf("%d", len(finder10.Nodes))
fmt.Printf("%d", len(finder11.Nodes))
fmt.Printf("%d", len(finder12.Nodes))
fmt.Printf("%d", len(finder13.Nodes))
fmt.Printf("%d", len(finder14.Nodes))
fmt.Printf("%d", len(finder15.Nodes))
fmt.Printf("%d", len(finder16.Nodes))
fmt.Printf("%d", len(finder17.Nodes))
fmt.Printf("%d", len(finder18.Nodes))
fmt.Printf("%d", len(finder19.Nodes))
fmt.Printf("%d", len(finder20.Nodes))
fmt.Printf("%d", len(finder21.Nodes))
fmt.Printf("%d", len(finder22.Nodes))
fmt.Printf("%d", len(finder23.Nodes))
}
Expected:
9(电影计数<section id="movieSection">
)Actual:
所有结果都返回 0。输出:000000000000000000000000
PS:当我通过 将结果打印到控制台时doc.Text()
,整个页面都会正确显示。
按顺序打印所有电影名称:
if len(myFinder.Nodes) > 0 {
doc.Find("MY QUERY").Each(func(i int, s *goquery.Selection) {
name := s.Find("a")
fmt.Println(name)
})
}