本文整理汇总了Java中com.gargoylesoftware.htmlunit.BrowserVersion.CHROME属性的典型用法代码示例。如果您正苦于以下问题:Java BrowserVersion.CHROME属性的具体用法?Java BrowserVersion.CHROME怎么用?Java BrowserVersion.CHROME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.gargoylesoftware.htmlunit.BrowserVersion
的用法示例。
在下文中一共展示了BrowserVersion.CHROME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchDuck
public static List<String> searchDuck (String keyword) {
List<String> searchResults = new ArrayList<>();
try{
WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page = webClient.getPage("https://duckduckgo.com/html/?q=" + keyword);
List<HtmlAnchor> l = page.getByXPath("//a[@class='result__url']");
for(HtmlAnchor a: l) {
searchResults.add(a.getHrefAttribute());
}
}
catch(Exception e){
System.err.println(e);
}
return searchResults;
}
示例2: getXenToken
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;
}
示例3: scrapingBaseExperiment
/**
* Scraping base experiment. To be used as starting point.
*
* First things first:
* <ol>
* <li>
* Make sure you're able to retrieve the page. Try again with JS disabled if
* the client crashes.
* </li>
* <li>
* Make sure you're actually getting what you want, and that there are no
* redirect-, proxy-, or login shenanigans or what not. Have a look at the
* retrieved text.
* </li>
* <li>
* Also consider disabling CSS to speed things up a bit.
* </li>
* </ol>
*/
@Test
public void scrapingBaseExperiment() {
assertOutputDirectoryExists();
String url = "http://www.google.com";
try (WebClient client = new WebClient(BrowserVersion.CHROME)) {
// client.getOptions().setCssEnabled(false);
// client.getOptions().setJavaScriptEnabled(false);
try {
HtmlPage page = client.getPage(url);
System.out.println("HtmlPage:");
System.out.println(page.asText());
System.out.print("\n");
} catch (IOException ex) {
System.err.println("WARNING: failed to visit: " + url);
ex.printStackTrace(System.err);
}
}
}
示例4: Server
public Server()throws IOException{
browser = new WebClient(BrowserVersion.CHROME);
problems = new ArrayList<>();
done = false;
isSubmitting = false;
user_name = "XC2";
pass_word = "donthackme";
work_list = new ArrayList<>();
users_data = new HashMap<>();
application = Executors.newCachedThreadPool();
//the buffer can be 100 at max (may be adjusted if needed)
buffer_queue = new LinkedBlockingQueue<>(100);
//some browser intitialization to increase efficiency (the cookies part is essential)
browser.getOptions().setUseInsecureSSL(true);
browser.getOptions().setJavaScriptEnabled(false);
browser.getOptions().setCssEnabled(false);
browser.getOptions().setThrowExceptionOnScriptError(false);
browser.getCookieManager().setCookiesEnabled(true);
browser.setAjaxController(new NicelyResynchronizingAjaxController());
}
示例5: main
public static void main(String[] args) throws IOException {
// 浏览器
WebClient 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响应时间,
// proxy
//webClient.getOptions().setProxyConfig(new ProxyConfig("IP", 80));
HtmlPage page = webClient.getPage("http://---");
String pageXml = page.asXml(); //以xml的形式获取响应文本
System.out.println(pageXml);
}
示例6: completeCloudflareBrowserCheck
public static Cookie completeCloudflareBrowserCheck(final String url) {
WebClient completeClient = new WebClient(BrowserVersion.CHROME);
completeClient.getOptions().setCssEnabled(false);
completeClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
final HtmlPage page;
final HtmlElement submitButton;
final HtmlForm challengeForm;
try {
page = completeClient.getPage(url);
completeClient.waitForBackgroundJavaScript(5000);
submitButton = (HtmlElement) page.createElement("button");
submitButton.setAttribute("type", "submit");
challengeForm = (HtmlForm) page.getElementById("challenge-form");
challengeForm.appendChild(submitButton);
submitButton.click();
return completeClient.getCookieManager().getCookie("cf_clearance");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例7: create
public static WebClient create() {
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(
Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http.client").setLevel(
Level.OFF);
// LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log","org.apache.commons.logging.impl.NoOpLog");
// java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setCssEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setTimeout(60000);
webClient.setJavaScriptTimeout(60000);
webClient.waitForBackgroundJavaScript(120000);
return webClient;
}
示例8: setUp
@Before
public void setUp() throws Exception {
System.out.println("Fake Google OAuth2 server up at: " + fakeGoogleServer.getEndpoint());
System.out.println("Fake Hackpad server up at: " + fakeHackpadServer.getEndpoint());
System.out.println("AwesomeAgile web application up at: " + getEndpoint());
fakeGoogleServer.setClientId(CLIENT_ID);
fakeGoogleServer.setClientSecret(CLIENT_SECRET);
fakeGoogleServer.setRedirectUriPrefixes(
ImmutableList.of("http://localhost:" + port + "/"));
fakeGoogleServer.setPerson(createUser());
fakeHackpadServer.setClientId(HACKPAD_CLIENT_ID);
fakeHackpadServer.setClientSecret(HACKPAD_CLIENT_SECRET);
fakeHackpadServer.getHackpads().clear();
fakeHackpadServer.addHackpad(
new PadIdentity(DEFINITION_OF_READY_TEMPLATE_ID),
DEFINITION_OF_READY_CONTENTS);
fakeHackpadServer.addHackpad(
new PadIdentity(DEFINITION_OF_DONE_TEMPLATE_ID),
DEFINITION_OF_DONE_CONTENTS);
driver = new HtmlUnitDriver(BrowserVersion.CHROME);
driver.setJavascriptEnabled(true);
}
示例9: testDashboardReopenBrowser
@Test
public void testDashboardReopenBrowser() throws Exception {
LandingPage landingPage = PageFactory.initElements(driver, LandingPage.class);
landingPage.loginWithGoogle(getEndpoint());
assertThat(driver.getWindowHandles(), hasSize(1));
landingPage.createDefinitionOfReady();
HtmlUnitDriver driverTwo = new HtmlUnitDriver(BrowserVersion.CHROME);
driverTwo.setJavascriptEnabled(true);
// Open a completely new browser with no cookies
// Verify that view button is visible for this same user,
// and we're able to open his Definition of ready hackpad
LandingPage landingPageTwo = PageFactory.initElements(driverTwo, LandingPage.class);
landingPageTwo.loginWithGoogle(getEndpoint());
landingPageTwo.waitForDefinitionOfReady();
assertTrue(landingPageTwo.isDefinitionOfReadyViewable());
landingPageTwo.viewDefinitionOfReady();
String newWindow = Iterables.getFirst(Sets.difference(
driverTwo.getWindowHandles(),
ImmutableSet.of(driverTwo.getWindowHandle())), null);
driverTwo.switchTo().window(newWindow);
HackpadPage hackpadPage = PageFactory.initElements(driverTwo, HackpadPage.class);
assertEquals(DEFINITION_OF_READY_CONTENTS, hackpadPage.getContent());
}
示例10: techFormTest
@Ignore
@Test
// TODO: This method of testing does not work for angular, need to find an alternative method of testing
public void techFormTest() {
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page;
String port = System.getProperty("liberty.test.port");
try {
page = webClient.getPage("http://localhost:" + port + "/start/");
DomElement techForm = page.getElementById("techTable");
DomElement formBody = techForm.getFirstElementChild();
int count = formBody.getChildElementCount();
// We expect there to be more than one child element, otherwise the
// javascript has not created the tech table properly.
assertTrue("Expected more than one element in the tech table, instead found " + count, count > 1);
} catch (Exception e){
org.junit.Assert.fail("Caught exception: " + e.getCause().toString());
} finally {
webClient.close();
}
}
示例11: setupBrowser
@Before
public void setupBrowser() {
webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(true);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
webClient.getOptions().setThrowExceptionOnScriptError(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setAppletEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setPopupBlockerEnabled(true);
webClient.getOptions().setTimeout(TIMEOUT);
webClient.getOptions().setPrintContentOnFailingStatusCode(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setAlertHandler(new AlertHandler() {
public void handleAlert(Page page, String message) {
System.err.println("[alert] " + message);
}
});
webClient.waitForBackgroundJavaScript(TIMEOUT);
}
示例12: initializeWebClient
/**
* initializes the WebClient object that will be used to fetch and parse web
* pages
*
* @return new instance of WebClient that can be used to load and parse
* pages
*/
private WebClient initializeWebClient(boolean minimal) {
WebClient client = null;
if (proxy != null && !proxy.trim().isEmpty()) {
client = new WebClient(BrowserVersion.CHROME, proxy, port);
} else {
client = new WebClient(BrowserVersion.CHROME);
}
if (minimal) {
client.getOptions().setAppletEnabled(false);
client.getOptions().setJavaScriptEnabled(false);
client.getOptions().setCssEnabled(false);
}
return client;
}
示例13: main
public static void main(String[] args) throws Exception {
//ģ��chorme��������������������BrowserVersion.����
WebClient webClient=new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
HtmlPage page=webClient.getPage("http://www.yanyulin.info");
//�������ָ��������ϻ�ȡ��ǩhed������
//HtmlDivision div=(HtmlDivision)page.getElementById("hed");
//System.out.println(div.asXml());
//ͬ�����Դ�ӡ��hed������,//div��//��ʾ���������ĵ��е�div,������Щdiv
//����list�У�Ȼ���ȡ��һ��div
//final HtmlDivision div = (HtmlDivision) page.getByXPath("//div").get(0);
//System.out.println(div.asXml());
java.util.List<HtmlAnchor> achList=page.getAnchors();
for(HtmlAnchor ach:achList){
System.out.println(ach.getHrefAttribute());
}
webClient.closeAllWindows();
}
示例14: main
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
// 屏蔽HtmlUnit等系统 log
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log","org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http.client").setLevel(Level.OFF);
String url = "https://www.douyin.com/share/video/6496703951436516621/?mid=6484356820260686606";
System.out.println("Loading page now-----------------------------------------------: "+url);
/* HtmlUnit 模拟浏览器 */
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(true); // 启用JS解释器,默认为true
webClient.getOptions().setCssEnabled(false); // 禁用css支持
webClient.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时,是否抛出异常
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setTimeout(10 * 1000); // 设置连接超时时间
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(30 * 1000); // 等待js后台执行30秒
String pageAsXml = page.asXml();
/* Jsoup解析处理 */
// Document doc = Jsoup.parse(pageAsXml, "https://bluetata.com/");
Document doc = Jsoup.parse(pageAsXml);
Elements pngs = doc.select("img[src$=.png]"); // 获取所有图片元素集
// 其他操作
System.out.println(doc.toString());
}
示例15: create
/**
* 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();
}