[英]Get the “Inspect Element” of a website by JAVA
當我使用 JAVA 按 F12 時,是否可以獲得顯示給我的“元素”代碼?
我最近需要從數千個具有相同編碼格式的網頁的元素代碼中獲取特定信息。
您可以使用 Selenium 來做到這一點:
WebClient webClient = new WebClient();
webClient.getOptions().setCssEnabled(false);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
String url = "https://www.google.com";
HtmlPage page = webClient.getPage(url);
System.out.println(page.asXml());
webClient.close();
包括依賴:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.40.0</version>
</dependency>
如果需要,包括任何其他依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.