如何在Golang中使用CSS选择器

发布于 2025-01-17 13:07:51 字数 1099 浏览 5 评论 0原文

在Ruby中,我有类似contents = html_doc.css(“ img + a”)的东西。我该怎么做?

我正在尝试使用Goquery,但我不确定如何转换它。具体来说,我尝试了doc.find(“ img”),但由于某种原因找不到任何东西

:这是我试图解析的http:

<img src="/icons/folder.gif" alt="[DIR]"> <a href="convobot-main/">convobot-main/</a>                    2022-01-27 13:55    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="matlab/">matlab/</a>                           2022-01-31 11:58    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="test/">test/</a>                             2022-01-27 13:52    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="test3%20-%20Copy/">test3 - Copy/</a>                     2022-02-09 15:09    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="test3/">test3/</a>                            2022-02-09 10:47    -
<img src="/icons/unknown.gif" alt="[   ]"> <a href="Quadractic.mlx">Quadractic.mlx</a>                    2022-01-21 15:02  3.3K
</pre>

我正在寻求获取诸如quadractic.mlx之类的文件名

In Ruby, I have something like contents = html_doc.css("img + a"). How would I do this in Go?

I am trying to use Goquery but I am unsure of how to convert it. Specifically, I tried doc.find("img") but it doesn't find anything for some reason

Edit: Here is the HTTP I'm trying to parse through:

<img src="/icons/folder.gif" alt="[DIR]"> <a href="convobot-main/">convobot-main/</a>                    2022-01-27 13:55    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="matlab/">matlab/</a>                           2022-01-31 11:58    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="test/">test/</a>                             2022-01-27 13:52    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="test3%20-%20Copy/">test3 - Copy/</a>                     2022-02-09 15:09    -
<img src="/icons/folder.gif" alt="[DIR]"> <a href="test3/">test3/</a>                            2022-02-09 10:47    -
<img src="/icons/unknown.gif" alt="[   ]"> <a href="Quadractic.mlx">Quadractic.mlx</a>                    2022-01-21 15:02  3.3K
</pre>

I am looking to get the file names like Quadractic.mlx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文