本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}