本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.setRedirectEnabled()
方法的一些代码示例,展示了WebClient.setRedirectEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.setRedirectEnabled()
方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:setRedirectEnabled
[英]Sets whether or not redirections will be followed automatically on receipt of a redirect status code from the server.
[中]设置从服务器收到重定向状态代码后是否自动执行重定向。
代码示例来源:origin: stackoverflow.com
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setTimeout(60000);
client.setRedirectEnabled(true);
client.setJavaScriptEnabled(true);
client.setThrowExceptionOnFailingStatusCode(false);
client.setThrowExceptionOnScriptError(false);
client.setCssEnabled(false);
client.setUseInsecureSSL(true);
代码示例来源:origin: stackoverflow.com
webClient.setJavaScriptEnabled(true);
webClient.setThrowExceptionOnScriptError(false);
webClient.setRedirectEnabled(false);
webClient.setAjaxController(new SyncAllAjaxController());
webClient.setCssErrorHandler(new SilentCssErrorHandler());
代码示例来源:origin: stackoverflow.com
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setTimeout(60000);
client.setRedirectEnabled(true);
client.setJavaScriptEnabled(true);
client.setThrowExceptionOnFailingStatusCode(false);
client.setThrowExceptionOnScriptError(false);
client.setCssEnabled(false);
client.setUseInsecureSSL(true);
HtmlPage page = null;
try {
page = client.getPage("http://www.whatever.com");
} catch (Exception e) {
// TODO Auto-generated catch block
}
if (page.getWebResponse().getStatusCode() == 404) {
System.out.println("Page not found");
}
// Post a request
WebRequest request = new WebRequest(new URL("http://www.whatever.com/post_url"));
request.setHttpMethod(HttpMethod.POST);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("login", userLogin));
params.add(new NameValuePair("pass", userPassword));
request.setRequestParameters(params);
page = client.getPage(request);
代码示例来源:origin: stackoverflow.com
public String getPageSourceFromBrowser(String url) throws SiteAnalizeException {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
HtmlPage firstPage = null;
String result = null;
try {
webClient.setJavaScriptEnabled(true);
webClient.setThrowExceptionOnScriptError(false);
webClient.setCssEnabled(false);
webClient.setUseInsecureSSL(false);
webClient.setRedirectEnabled(true);
firstPage = webClient.getPage(new URL(url));
result = firstPage.getWebResponse().getContentAsString("UTF-8");
DomNodeList<HtmlElement> button = firstPage.getElementsByTagName("a");
for (HtmlElement htmlElement : button) {
if(htmlElement.asText().equals("Buy Now")) {
HtmlPage page = htmlElement.click();
//HtmlElement button2 = page.getElementById("market_buynow_dialog_addfunds");
//HtmlPage page2 = button2.click();
String htmlBody = page.getWebResponse().getContentAsString();
System.out.println(htmlBody);
}
}
}
代码示例来源:origin: org.scribe/scribe-up
public static WebClient newWebClient(boolean isJavascriptEnabled) {
WebClient webClient = new WebClient();
webClient.setRedirectEnabled(true);
webClient.setCssEnabled(false);
webClient.setJavaScriptEnabled(isJavascriptEnabled);
return webClient;
}
代码示例来源:origin: org.openqa.selenium.webdriver/webdriver-htmlunit
private WebClient createWebClient(BrowserVersion version) {
WebClient client = newWebClient(version);
client.setThrowExceptionOnFailingStatusCode(false);
client.setPrintContentOnFailingStatusCode(false);
client.setJavaScriptEnabled(enableJavascript);
client.setRedirectEnabled(true);
try {
client.setUseInsecureSSL(true);
} catch (GeneralSecurityException e) {
throw new WebDriverException(e);
}
// Ensure that we've set the proxy if necessary
if (proxyConfig != null)
client.setProxyConfig(proxyConfig);
return modifyWebClient(client);
}
内容来源于网络,如有侵权,请联系作者删除!