如何在 jsoup 中找到带有 pseudoElement ::before 的 HTML 标签
How can I find a HTML tag with the pseudoElement ::before in jsoup
我将使用 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 解决这个问题?
非常感谢
好的。我又看了一些资料。
JavaScript 将内容添加到 html 代码中。 Jsoup 不支持 JavaScript。所以 Jsoup 是不可能的。
我会尝试使用其他工具,如 Selenium。
谢谢。
我将使用 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 解决这个问题?
非常感谢
好的。我又看了一些资料。
JavaScript 将内容添加到 html 代码中。 Jsoup 不支持 JavaScript。所以 Jsoup 是不可能的。
我会尝试使用其他工具,如 Selenium。
谢谢。