问题
I will read the img links from a website with jsoup. When I search the HTML code I find the links in a ::before (https://developer.mozilla.org/en-US/docs/Web/CSS/::before) element like
::before
<span>
<img src="https://link.png" alt="">
</span>
My Java Code:
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());
}
}
I got no results in the class="thumb-block". If I look at the HTML code i can see:
<div class="thumb-block">
::before
<span>
<img src="https:link" alt="DMC-LX100 Premium-Kompaktkamera Bild für Miniaturansicht 2">
</span>
</div>
In the jsoup result I got no tags which starts with the ::before element. Has anyone an idea, how I can fix this with jsoup?
Thank you so much
回答1:
Okay. I read some more informations.
The content is added to the html-code by JavaScript. Jsoup don't support JavaScript. So it is not possible with Jsoup.
I will try it with an other tool like Selenium.
Thank you.
来源:https://stackoverflow.com/questions/60785706/how-can-i-find-a-html-tag-with-the-pseudoelement-before-in-jsoup