【问题标题】:How can I find a HTML tag with the pseudoElement ::before in jsoup如何在 jsoup 中找到带有伪元素 ::before 的 HTML 标记
【发布时间】:2020-07-02 06:31:48
【问题描述】:

我将使用 jsoup 从网站读取 img 链接。当我搜索 HTML 代码时,我在 ::before 中找到了链接 (https://developer.mozilla.org/en-US/docs/Web/CSS/::before) 元素喜欢

::before 
<span>
<img src="https://link.png" alt=""> 
</span>

我的 Java 代码:

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class JavaApplication6 {

    public static void main(String[] args) throws IOException {

            String link = "https://www.panasonic.com/de/consumer/foto-video/lumix-kompaktkameras/dmc-lx100.html";

            Document docHauptseite = Jsoup.connect(link)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1")
                    .referrer("http://www.google.com")
                    .followRedirects(true)
                    .get();


            Elements sImages = docHauptseite.getElementsByClass("thumb-block");
            System.out.println("sImages count = " + sImages.size());

            Elements sImagesFeatures = docHauptseite.getElementsByClass("featureslide650image");
            System.out.println("sImagesFeatures count = " + sImagesFeatures.size());



    }
}

我在 class="thumb-block" 中没有得到任何结果。如果我查看 HTML 代码,我可以看到:

<div class="thumb-block">
::before
    <span>
        <img src="https:link" alt="DMC-LX100 Premium-Kompaktkamera Bild für Miniaturansicht 2">
    </span>
</div>

在 jsoup 结果中,我没有得到以 ::before 元素开头的标签。有谁知道如何用 jsoup 解决这个问题?

非常感谢

【问题讨论】:

标签: java html jsoup pseudo-element


【解决方案1】:

好的。我阅读了更多信息。

内容通过 JavaScript 添加到 html 代码中。 Jsoup 不支持 JavaScript。所以 Jsoup 是不可能的。

我将尝试使用 Selenium 等其他工具。

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多