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

x33g5p2x  于2022-02-03 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(129)

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

WebClientOptions.setCssEnabled介绍

[英]Enables/disables CSS support. By default, this property is enabled. If disabled HtmlUnit will not download the linked css files and also not triggered the associated onload/onerror events.
[中]启用/禁用CSS支持。默认情况下,此属性处于启用状态。如果禁用HtmlUnit,它将不会下载链接的css文件,也不会触发相关的onload/onerror事件。

代码示例

代码示例来源: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: out0fmemory/GuozhongCrawler

public ExtendWebDriver(boolean enableJavascript) {
  this(BrowserVersion.CHROME);
  headerNames = new HashSet<String>();
  if(enableJavascript){
    setJavascriptEnabled(enableJavascript);
    WebClient webClient = getWebClient();
    webClient.getOptions().setCssEnabled(false);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    //webClient.getOptions().setTimeout(50000);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
  }
}

代码示例来源:origin: ksahin/introWebScraping

String baseUrl = "https://newyork.craigslist.org/" ;
WebClient client = new WebClient();
client.getOptions().setCssEnabled(false);
client.getOptions().setJavaScriptEnabled(false);
try {

代码示例来源:origin: openaudible/openaudible

this.getOptions().setCssEnabled(false);//if you don't need css

代码示例来源:origin: ArcBees/GWTP

webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);

代码示例来源:origin: com.gwtplatform/gwtp-crawler-service

webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);

代码示例来源: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: com.atlassian.confluence/jwebunit-confluence-plugin

@Override
protected WebClient createWebClient() {
  WebClient webClient = new WebClient(GLOBAL_CONFIG.getBrowserVersion());
  webClient.setWebConnection(new ConfluenceWebConnection(webClient, MAX_CONNECTIONS, GLOBAL_CONFIG));
  webClient.setCache(WEBCLIENT_REQUEST_CACHE);
  webClient.getOptions().setTimeout(GLOBAL_CONFIG.getHttpRequestTimeoutMillis());
  webClient.getOptions().setCssEnabled(false);
  webClient.getOptions().setPrintContentOnFailingStatusCode(false);
  return webClient;
}

代码示例来源:origin: com.synaptix.redpepper/redpepper-automation

@Override
  protected WebClient modifyWebClient(WebClient client) {
    myClient = client;
    client.getCookieManager().setCookiesEnabled(true);
    client.getOptions().setJavaScriptEnabled(true);
    client.getOptions().setCssEnabled(true);
    client.getOptions().setPopupBlockerEnabled(false);
    client.setIncorrectnessListener(new SilentIncorrectnessListener());
    client.setCssErrorHandler(new QuietCssErrorHandler());
    client.setAjaxController(new NicelyResynchronizingAjaxController());
    return client;
  }
}

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

webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);

代码示例来源:origin: ksahin/introWebScraping

public static WebClient autoLogin(String loginUrl, String login, String password) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
  WebClient client = new WebClient();
  client.getOptions().setCssEnabled(false);
  client.getOptions().setJavaScriptEnabled(false);
  
  HtmlPage page = client.getPage(loginUrl);
  
  HtmlInput inputPassword = page.getFirstByXPath("//input[@type='password']");
  //The first preceding input that is not hidden
  HtmlInput inputLogin = inputPassword.getFirstByXPath(".//preceding::input[not(@type='hidden')]");
  
  inputLogin.setValueAttribute(login);
  inputPassword.setValueAttribute(password);
  
  //get the enclosing form
  HtmlForm loginForm = inputPassword.getEnclosingForm() ;
  
  //submit the form
  page = client.getPage(loginForm.getWebRequest(null));
  
  //returns the cookies filled client :)
  return client;
}

相关文章