當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。