当前位置: 首页>>代码示例>>Java>>正文


Java WebClient.close方法代码示例

本文整理汇总了Java中com.gargoylesoftware.htmlunit.WebClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java WebClient.close方法的具体用法?Java WebClient.close怎么用?Java WebClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.gargoylesoftware.htmlunit.WebClient的用法示例。


在下文中一共展示了WebClient.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getXenToken

import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
private String getXenToken(final Account account) { // TODO: Re-write this if it ever gets used
    final WebClient webClient = new WebClient(BrowserVersion.CHROME);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setJavaScriptEnabled(false);

    final HtmlPage page;
    final HtmlInput token;

    account.getCookies().forEach(c -> webClient.getCookieManager().addCookie(c));

    try {
        page = webClient.getPage(account.getForum().getProtocol() + "://" + account.getForum());
        token = page.getFirstByXPath("//*[@id='XenForo']/body/div[1]/aside[2]/div/div/div[1]/div[2]/form/div/input[2]");

        webClient.close();
        return token.getValueAttribute();
    } catch (Exception e) {
        e.printStackTrace();
    }
    webClient.close();
    return null;
}
 
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:23,代码来源:StatViewController.java

示例2: getHtmlPageHtmlUnit

import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
/**
 * HtmlUnit을 이용한 HTML 코드 파싱.
 * @param eachArchiveAddress 실제 만화가 담긴 아카이브 주소
 * @return 성공 시 html 코드를 리턴
 */
private String getHtmlPageHtmlUnit(String eachArchiveAddress) throws Exception {
	/* 필수! 로그 메세지 출력 안함 -> HtmlUnit 이용시 Verbose한 로그들이 너무 많아서 다 끔 */
	java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
	System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
	
	System.out.print("일반 연결 시도중 ... ");
	
	WebClient webClient = new WebClient();
	webClient.getOptions().setRedirectEnabled(true);
	
	WebRequest req = new WebRequest(new URL(eachArchiveAddress));
	req.setHttpMethod(HttpMethod.POST);
	req.setAdditionalHeader("User-Agent", UserAgent.getUserAgent());
	req.setAdditionalHeader("Accept-Encoding", "gzip"); //20171126 gzip 추가
	req.getRequestParameters().add(new NameValuePair("pass", PASSWORD)); //비밀번호 post 방식 전송
	
	HtmlPage page = webClient.getPage(req);
	
	//Html코드를 포함한 페이지 소스코드가 담길 스트링
	String pageSource = page.asXml();
	
	/** 여기도 페이지 파싱 실패 시 검증하는 코드 들어가야 됨 **/
	
	webClient.close();
	System.out.println("성공");
	return pageSource;
}
 
开发者ID:occidere,项目名称:MMDownloader,代码行数:33,代码来源:Downloader.java

示例3: create

import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
/**
 * Starts the CSV link creation process.
 * 
 * @throws Exception If there was an error while getting the CSV specific information from the forum thread.
 */
public void create() throws Exception{
	java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);
	
	WebClient webClient = new WebClient(BrowserVersion.CHROME);
    HtmlPage page = (HtmlPage) webClient.getPage(forumThreadLink);
    webClient.waitForBackgroundJavaScriptStartingBefore(waitForJavaScript);
    HtmlAnchor anchor = (HtmlAnchor) page.getByXPath(xPath).get(0);
    csvFileLink = anchor.getHrefAttribute();
    csvFileLink = "http://www.pathofexile.com" + csvFileLink.subSequence(0, csvFileLink.length()-1);
    webClient.close();  
}
 
开发者ID:jkjoschua,项目名称:poe-ladder-tracker-java,代码行数:17,代码来源:CSVLinkCreator.java

示例4: getNextUrl

import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
/**
 * 通过htmlunit来获得一些搜狗的网址。
 * @param key
 * @return
 * @throws Exception
 */
public String getNextUrl(String key){
	String page = new String();
	try {
		WebClient webClient = new WebClient();
		webClient.getOptions().setCssEnabled(false);
		webClient.getOptions().setJavaScriptEnabled(false);
		
		//去拿网页
		HtmlPage htmlPage = webClient.getPage("http://pic.sogou.com/");
		//得到表单
		HtmlForm form = htmlPage.getFormByName("searchForm");
		//得到提交按钮
		HtmlSubmitInput button = form.getInputByValue("搜狗搜索");
		//得到输入框

		HtmlTextInput textField = form.getInputByName("query");
		//输入内容
		textField.setValueAttribute(key);
		//点一下按钮
		HtmlPage nextPage = button.click();

		String str = nextPage.toString();
		page = cutString(str);
		webClient.close();
	} catch (Exception e) {
		// TODO: handle exception
	} finally{
		
	}
	System.out.println();
	return page;
	
}
 
开发者ID:anLA7856,项目名称:Crawler,代码行数:40,代码来源:CrawUrl.java

示例5: obtainPersonas

import com.gargoylesoftware.htmlunit.WebClient; //导入方法依赖的package包/类
public Persona obtainPersonas(String host)
    throws FailingHttpStatusCodeException, MalformedURLException,
    IOException {
  if (this.patterns == null
      || (this.patterns != null && this.patterns.isEmpty()))
    initPatterns();

  WebClient webClient = new WebClient();
  webClient.getOptions().setJavaScriptEnabled(false);
  webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  HtmlPage htmlPage = null;
  Persona persona = new Persona();
  persona.setHostPatternKey(host);
  ;
  persona.setPageId(page.toURI().toString());

  try {
    htmlPage = webClient.getPage(page.toURL());
  } catch (Exception e) {
    e.printStackTrace(System.out);
    webClient.close();
    return persona;
  }

  String pattern = patterns.get(host);
  boolean isAnchor = false;
  if (pattern.contains("@href")) {
    isAnchor = true;
  }

  List<?> elements = htmlPage.getByXPath(patterns.get(host));
  for (int i = 0; i < elements.size(); i++) {
    String username = null;
    if (isAnchor) {
      String link = ((HtmlAnchor) elements.get(i)).getHrefAttribute();
      if (isUserLink(link)) {
        int index = link.lastIndexOf('/');
        username = link.substring(index + 1);
      }
    } else {
      if (elements.get(i) instanceof String) {
        username = ((String) elements.get(i)).trim();
      } else {
        username = ((DomNode) elements.get(i)).asText();
      }
    }

    if (username != null && !username.equals("")) {
      persona.getUsernames().add(username);
    }

  }

  webClient.close();
  return persona;
}
 
开发者ID:USCDataScience,项目名称:PersonaExtraction,代码行数:58,代码来源:PersonaExtractor.java


注:本文中的com.gargoylesoftware.htmlunit.WebClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。