英文:
Scrape discription from web site go-colly
问题
我尝试从img网站上爬取描述信息,但我不明白如何获取。以下是我的尝试:
pg := Program{}
slPG := []Program{}
c.OnHTML(".short", func(e *colly.HTMLElement) {
pg.Name = e.ChildText("h2.short-cat")
pg.Link = e.ChildAttr("a", "href")
pg.Rating = e.ChildText("a.orating_res")
pg.Discription = e.ChildText("div.short-text full-text video-box clearfix")
slPG = append(slPG, pg)
})
for i := 1; i < 6; i++ {
c.Visit("https://rsload.net/page/" + strconv.Itoa(i) + "/")
}
file, err := json.MarshalIndent(slPG, "", " ")
if err != nil {
log.Println("无法创建'json'文件")
return
}
_ = ioutil.WriteFile("files/Export.json", file, 0644)
英文:
I try scrape the description from website
img, but I not understand how to get there <br>
My trying
pg := Program{}
slPG := []Program{}
c.OnHTML(".short", func(e *colly.HTMLElement) {
pg.Name = e.ChildText("h2.short-cat")
pg.Link = e.ChildAttr("a", "href")
pg.Rating = e.ChildText("a.orating_res")
pg.Discription = e.ChildText("div.short-text full-text video-box clearfix")
slPG = append(slPG, pg)
})
for i := 1; i < 6; i++ {
c.Visit("https://rsload.net/page/" + strconv.Itoa(i) + "/")
}
file, err := json.MarshalIndent(slPG, "", " ")
if err != nil {
log.Println("Unable to create 'json' file")
return
}
_ = ioutil.WriteFile("files/Export.json", file, 0644)
答案1
得分: 1
请展示更多你的代码。具体来说,你需要展示你想要抓取的HTML部分。
我知道你有一部分文本和属性,但是colly库非常挑剔。如果你没有完全正确的信息,它将不会返回任何内容给你。
你是通过命令行中的fmt获取信息,还是将其解析成GUI,或者将其全部转换成文件?提供更多信息,我们可以提供帮助。
英文:
Please show more of your code. Specifically, you need to show the part of the html which you are trying to grab.
I know you have a part of the text and attributes, but the colly library is very picky. If you don't have exactly the right info. It will return nothing back to you.
Are you getting the information back via fmt in command line, or parsing it into a gui, or perhaps converting it all into a file? Provide more info and we can help.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论