我正在尝试使用下面的代码解析链接 http://finance.yahoo.com/quote/VZ/key-statistics?p=VZ ,并且页面未完全加载。我尝试过使用 webClient.waitForBackgroundJavaScript(500000); & Thread.sleep(1000); 没有任何成功。我的目标是阅读评估措施下的表格内容,但永远不会加载。任何帮助表示赞赏。
import java.sql.Timestamp;
import java.util.ArrayList;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class LocalScreenScappingTest {
public static void main(String[] args) {
try {
java.util.logging.Logger.getLogger("com.gargoylesoftware")
.setLevel(java.util.logging.Level.OFF);
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setPrintContentOnFailingStatusCode(false);
// webClient.waitForBackgroundJavaScript(500000);
HtmlPage page = webClient
.getPage("http://finance.yahoo.com/quote/VZ/key-statistics?p=VZ");
// Thread.sleep(1000);
System.out.println(page.asText());
// HtmlTable table = (HtmlTable)
// page.getFirstByXPath("//*[@id='main-0-Quote-Proxy']/section/div[2]/section/div/section/div[2]/div[1]/div[1]/div/table");
} catch (Exception ex) {
System.out.println((new Timestamp(new java.util.Date().getTime()))
+ ": " + ex.toString());
}
}
}