com.gargoylesoftware.htmlunit.WebClient.setJavaScriptTimeout()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 JavaScript  
字(5.6k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.setJavaScriptTimeout()方法的一些代码示例,展示了WebClient.setJavaScriptTimeout()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.setJavaScriptTimeout()方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:setJavaScriptTimeout

WebClient.setJavaScriptTimeout介绍

[英]Sets the number of milliseconds that a script is allowed to execute before being terminated. A value of 0 or less means no timeout.
[中]设置脚本在终止前允许执行的毫秒数。值为0或更小表示没有超时。

代码示例

代码示例来源:origin: mrdear/JavaWEB

WebClientUtil() {
    webClient = new WebClient(BrowserVersion.CHROME);
    webClient.getOptions().setUseInsecureSSL(true);//支持https
    webClient.getOptions().setJavaScriptEnabled(true); // 启用JS解释器,默认为true
    webClient.getOptions().setCssEnabled(false); // 禁用css支持
    webClient.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时,是否抛出异常
    webClient.getOptions().setTimeout(10000); // 设置连接超时时间 ,这里是10S。如果为0,则无限期等待
    webClient.getOptions().setDoNotTrackEnabled(false);
    webClient.setJavaScriptTimeout(8000);//设置js运行超时时间
    webClient.waitForBackgroundJavaScript(500);//设置页面等待js响应时间,
  }
}

代码示例来源:origin: stackoverflow.com

final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17,
        PROXY_HOST, PROXY_PORT);

WebRequest request = new WebRequest(new URL(
        "http://steamcommunity.com/id/bobcatchris/inventory#730"));

webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setJavaScriptTimeout(10000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setTimeout(10000);

HtmlPage page = webClient.getPage(request);

     String script="var list = [];\n" +
          "\n" +
          "\n" +
          "var size = Object.keys(g_ActiveInventory.rgInventory).size();\n" +
          "\n" +
          "\n" +
          "\n" +
          "var counter = 0;\n" +
          "\n" +
          "while (counter < size) {\n" +
          " list.push(g_ActiveInventory.rgInventory[Object.keys(g_ActiveInventory.rgInventory)[counter]].market_name);\n" +
          " counter +=1;\n" +
          "}";
      Object result = page.executeJavaScript(script).getJavaScriptResult();
      System.out.println(result);

代码示例来源:origin: stackoverflow.com

webClient.setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setJavaScriptTimeout(20000);
webClient.waitForBackgroundJavaScript(20000);

代码示例来源:origin: stackoverflow.com

webClient.setJavaScriptTimeout(10000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());

代码示例来源:origin: stackoverflow.com

final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17,
       YOUR_PROXY_HOST, YOUR_PROXY_PORT);
   WebRequest request = new WebRequest(
       new URL(
           "http://bitcoincharts.com/charts/btceUSD#rg60ztgSzm1g10zm2g25zv"));
   webClient.getOptions().setThrowExceptionOnScriptError(false);
   webClient.setJavaScriptTimeout(10000);
   webClient.getOptions().setJavaScriptEnabled(true);
   webClient.setAjaxController(new NicelyResynchronizingAjaxController());
   webClient.getOptions().setTimeout(10000);
   HtmlPage page = webClient.getPage(request);
   webClient.waitForBackgroundJavaScript(30000);
   List<HtmlAnchor> anchors1 = page.getAnchors();
   HtmlAnchor link2 = null;
   for (HtmlAnchor anchor : anchors1) {
     //System.out.println(anchor.asText());
     if (anchor.asText().indexOf("Load raw data") > -1) {
       link2 = anchor;
       break;
     }
   }
   page = link2.click();

代码示例来源:origin: USCDataScience/sparkler

@Override
public void init(JobContext context, String pluginId) throws SparklerException {
  super.init(context, pluginId);
  //TODO: get timeouts from configurations
  driver = new WebClient(BrowserVersion.BEST_SUPPORTED);
  driver.setJavaScriptTimeout(DEFAULT_JS_TIMEOUT);
  WebClientOptions options = driver.getOptions();
  options.setCssEnabled(false);
  options.setAppletEnabled(false);
  options.setDownloadImages(false);
  options.setJavaScriptEnabled(true);
  options.setTimeout(DEFAULT_TIMEOUT);
  options.setUseInsecureSSL(true);
  options.setPopupBlockerEnabled(true);
  options.setDoNotTrackEnabled(true);
  options.setGeolocationEnabled(false);
  options.setHistorySizeLimit(2);
  options.setPrintContentOnFailingStatusCode(false);
  options.setThrowExceptionOnScriptError(false);
  options.setThrowExceptionOnFailingStatusCode(false);
  if (this.httpHeaders != null && !this.httpHeaders.isEmpty()) {
    LOG.info("Found {} headers", this.httpHeaders.size());
    this.httpHeaders.forEach((name, val) -> driver.addRequestHeader(name, val));
  } else {
    LOG.info("No user headers found");
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args)
     throws FailingHttpStatusCodeException, IOException {
   final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);
   WebRequest request = new WebRequest(new URL(
       "http://www.firstpost.com/tag/crime-in-india"));
   webClient.getOptions().setThrowExceptionOnScriptError(false);
   webClient.setJavaScriptTimeout(10000);
   webClient.getOptions().setJavaScriptEnabled(true);
   webClient.setAjaxController(new NicelyResynchronizingAjaxController());
   webClient.getOptions().setTimeout(10000);
   HtmlPage page = webClient.getPage(request);
   webClient.waitForBackgroundJavaScript(10000);
   List<HtmlAnchor> anchors1 = page.getAnchors();
   HtmlAnchor link2 = null;
   for (HtmlAnchor anchor : anchors1) {
     if (anchor.asText().indexOf(
         "Why do we care more when NRIs go missing?") > -1) {
       link2 = anchor;
       break;
     }
   }
   page = link2.click();
   webClient.waitForBackgroundJavaScript(10000);
   DomNodeList<DomElement> paras = page.getElementsByTagName("p");
   for (DomElement el : paras.toArray(new DomElement[paras.size()])) {
     System.out.println(el.asText());
   }
 }

代码示例来源:origin: xuxueli/xxl-crawler

webClient.setJavaScriptTimeout(pageRequest.getTimeoutMillis());
webClient.waitForBackgroundJavaScript(pageRequest.getTimeoutMillis());

相关文章

WebClient类方法