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


Java BrowserVersion类代码示例

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


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

示例1: searchDuck

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
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;
}
 
开发者ID:nitroignika,项目名称:duck-feed-2,代码行数:18,代码来源:DuckScrape.java

示例2: getXenToken

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的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

示例3: scrapingBaseExperiment

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
/**
	 * 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);
			}
		}
	}
 
开发者ID:limstepf,项目名称:pdfdbscrap,代码行数:41,代码来源:HtmlUnitExperiments.java

示例4: Server

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
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());
}
 
开发者ID:AmrSaber,项目名称:XC2,代码行数:23,代码来源:Server.java

示例5: main

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
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);

    }
 
开发者ID:xuxueli,项目名称:xxl-incubator,代码行数:22,代码来源:Demo.java

示例6: completeCloudflareBrowserCheck

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
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;
    }
}
 
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:27,代码来源:LoginViewController.java

示例7: create

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
public static WebClient create(String host,int port) {
	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.FIREFOX_17,host,port);
	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;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:24,代码来源:HtmlUnitUtil.java

示例8: setUp

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
@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);
}
 
开发者ID:cs71-caffeine,项目名称:awesome-agile,代码行数:24,代码来源:AwesomeAgileFunctionalTest.java

示例9: testDashboardReopenBrowser

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
@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());
}
 
开发者ID:cs71-caffeine,项目名称:awesome-agile,代码行数:26,代码来源:AwesomeAgileFunctionalTest.java

示例10: testPost

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
@Test
public void testPost() throws Exception {
	cfg.setProperty(WSFedConstants.PROP_USE_REDIRECT, false);

	StringWriter sw = new StringWriter();
	when(res.getWriter()).thenReturn(new PrintWriter(sw));
	
	LoginHandler lh = new LoginHandler();
	lh.handleGet(rc);
	
	WebWindow win = mock(WebWindow.class);
	when(win.getScriptObject()).thenThrow(new RuntimeException("test"));
	when(win.getWebClient()).thenReturn(new WebClient(BrowserVersion.FIREFOX_2));
	
	DOMParser parser = new DOMParser();
	parser.parse(new InputSource(new ByteArrayInputStream(sw.toString().getBytes())));
	HTMLElement e = (HTMLElement) parser.getDocument().getDocumentElement();
	
	NodeList forms = e.getElementsByTagName("form");
	assertEquals(1, forms.getLength());
	Element form = (Element)forms.item(0);
	assertEquals("loginform", form.getAttribute("name"));
	assertEquals(rc.getIdpMetadata().getFirstMetadata().getSingleSignonServiceLocation(WSFedConstants.WSFED_PROTOCOL), form.getAttribute("action"));
	
	verify(res, never()).sendRedirect(anyString());
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:27,代码来源:LoginHandlerTest.java

示例11: getBrowserEnum

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public BrowserVersion getBrowserEnum() {
       if (browserName.equals("Mozilla Firefox 3.6")) {
           return BrowserVersion.FIREFOX_3_6;
       }
       else if (browserName.equals("Mozilla Firefox 10")) {
           return BrowserVersion.FIREFOX_10;
       }
       else if (browserName.equals("Mozilla Firefox 17")) {
           return BrowserVersion.FIREFOX_17;
       }
       else if (browserName.equals("IE 6")) {
           return BrowserVersion.INTERNET_EXPLORER_6;
       } else if (browserName.equals("IE 7")) {
           return BrowserVersion.INTERNET_EXPLORER_7;
       } else if (browserName.equals("IE 8")) {
           return BrowserVersion.INTERNET_EXPLORER_8;
       }
       else if (browserName.equals("IE 9")) {
           return BrowserVersion.INTERNET_EXPLORER_9;
       }
       else if (browserName.equals("IE 10")) {
           return BrowserVersion.INTERNET_EXPLORER_10;
       }        
       return BrowserVersion.getDefault();
   }
 
开发者ID:fanghon,项目名称:webmonitor,代码行数:27,代码来源:Configuration.java

示例12: techFormTest

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:WASdev,项目名称:tool.accelerate.core,代码行数:22,代码来源:PageFunctionTest.java

示例13: getLocker

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
public List<LockerObject> getLocker(boolean previewLink) {
	List<LockerObject> list = new ArrayList<>();
	try {
		WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
		webClient.setCookieManager(cookieManager);

		HtmlPage page = webClient.getPage("https://pdsb.elearningontario.ca/d2l/lms/locker/locker.d2l?ou=8340");

		for (Object object : page.getByXPath("//a")) {
			DomElement de = (DomElement) object;
			if (de.asXml().toString().contains("/d2l/common/viewFile.d2lfile/Database/")) {
				if (!previewLink) {
					list.add(new LockerObject(de.getAttribute("title").replace("Open ", ""),  "https://pdsb.elearningontario.ca" + de.getAttribute("href").replace("&display=1", "")));
				} else {
					list.add(new LockerObject(de.getAttribute("title").replace("Open ", ""),  "https://pdsb.elearningontario.ca" + de.getAttribute("href")));

				}
			}
		}

		webClient.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return list;
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:27,代码来源:D2LHook.java

示例14: getNotifications

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
public List<NotificationObject> getNotifications(String ID) throws InvaildCourseException {
	List<NotificationObject> list = new ArrayList<>();
	try {
		WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
		webClient.setCookieManager(cookieManager);

		UnexpectedPage page = webClient.getPage("https://pdsb.elearningontario.ca/d2l/MiniBar/" + ID + "/ActivityFeed/GetAlerts?Category=1&_d2l_prc%24headingLevel=2&_d2l_prc%24scope=&_d2l_prc%24hasActiveForm=false&isXhr=true&requestId=2");
		NotificationFormater notificationFormater = new NotificationFormater(page.getWebResponse().getContentAsString());
		
		webClient.close();
		
		for (Object object: notificationFormater.getNotifications()) {
			DomElement de = (DomElement) object;
			String[] split = de.asText().split("\\n");
			
			list.add(new NotificationObject(split[0].trim(), split[1].trim(), split[2].trim()));
		}
	} catch (Exception e) {
		throw new InvaildCourseException("Invaild Course ID");
	}
	
	return list;
}
 
开发者ID:zeshan321,项目名称:Project-D2L,代码行数:24,代码来源:D2LHook.java

示例15: getLeboncoin

import com.gargoylesoftware.htmlunit.BrowserVersion; //导入依赖的package包/类
private static WebClient getLeboncoin()
{
    final WebClient client = new WebClient(BrowserVersion.FIREFOX_17);
    try
    {
        client.getOptions().setJavaScriptEnabled(true);
        client.getOptions().setAppletEnabled(false);
        client.getOptions().setCssEnabled(false);
        client.getOptions().setPrintContentOnFailingStatusCode(true);
        client.getOptions().setPopupBlockerEnabled(true);
        client.getOptions().setThrowExceptionOnScriptError(false);
        client.getOptions().setUseInsecureSSL(true);
    }
    catch (Exception e)
    {
        Logger.traceERROR(e);
    }

    return client;
}
 
开发者ID:philipperemy,项目名称:Leboncoin,代码行数:21,代码来源:Client.java


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