登录
首页 >  Golang >  Go问答

解决 go-colly 中的 noscript 问题

来源:stackoverflow

时间:2024-02-29 11:39:20 327浏览 收藏

小伙伴们有没有觉得学习Golang很有意思?有意思就对了!今天就给大家带来《解决 go-colly 中的 noscript 问题》,以下内容将会涉及到,若是在学习中对其中部分知识点有疑问,或许看了本文就能帮到你!

问题内容

所以我正在从网站制作一个抓取脚本。仅当抓取文本成功时,仅当抓取图像失败时。当我检查元素时,代码仍然正常,但是当我运行视图源时,图像包装代码更改为无脚本。所以我想是这样的,也许有人可以帮忙?

c.onhtml(".postarea", func(h *colly.htmlelement) {
        as := image{}
        as.name = h.childtext(".headpost .entry-title")
        h.foreach(".maincontent", func(i int, x *colly.htmlelement) {
            ya := so{}
            ya.url = x.childattr("#readerarea img", "src")
            as.image = append(as.image, ya)
        })
        b, err := json.marshalindent(as, "", " ")
        if err != nil {
            log.println("failed to serialize response:", err)
            return
        }
        w.header().add("content-type", "application/json")
        w.write(b)
    })
    c.onrequest(

这是示例 html 代码。


解决方案


页面上将有一些 JavaScript 来更新此内容(

Go-Colly 不运行 JavaScript,因此您需要另一种方法。选项包括查看 JavaScript 以了解它如何定位图像或使用 chromedp 等内容代替 go-colly。

理论要掌握,实操不能落!以上关于《解决 go-colly 中的 noscript 问题》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>