當前位置: 首頁>>代碼示例>>Java>>正文


Java HtmlPage.getFirstByXPath方法代碼示例

本文整理匯總了Java中com.gargoylesoftware.htmlunit.html.HtmlPage.getFirstByXPath方法的典型用法代碼示例。如果您正苦於以下問題:Java HtmlPage.getFirstByXPath方法的具體用法?Java HtmlPage.getFirstByXPath怎麽用?Java HtmlPage.getFirstByXPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.gargoylesoftware.htmlunit.html.HtmlPage的用法示例。


在下文中一共展示了HtmlPage.getFirstByXPath方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getXenToken

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的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: setAttribute

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
public static boolean setAttribute(HtmlPage htmlPage, String xpath,
		String key, String value) {
	boolean flag = true;
	try {
		HtmlElement element = htmlPage.getFirstByXPath(xpath);
		if (element != null) {
			element.click();
			element.setAttribute(key, "");
			element.setAttribute(key, value);
		} else {
			logger.error("setAttribute element is null xpath " + xpath);
		}

	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		flag = false;
	}
	return flag;
}
 
開發者ID:xiaomin0322,項目名稱:alimama,代碼行數:20,代碼來源:HtmlUnitUtil.java

示例3: UpdateAbstract

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
public boolean UpdateAbstract()
{
	WebClient webClient = new WebClient(BrowserVersion.CHROME);
	logMessage = "UpdateAbstract:<br/>";
	
	try
	{
		List<Paper> papers = Paper.list();
		
		for (int i = 0; i < papers.size(); i++) 
		{
			if(papers.get(i).abstract_text!= null && papers.get(i).abstract_text.length()>=1)
   			    continue;

			HtmlPage Page = webClient.getPage( papers.get(i).abstract_url );

			HtmlElement element = Page.getFirstByXPath( "/html/body/div[@id='content']/dl/dd/div[@id='abstract']" );
			if( element != null)
			{
				papers.get(i).abstract_text = element.getTextContent();
				papers.get(i).update();
				logger.info("updated abstract_text:" + i);
			}	
		}
	}
	catch(Exception e)
	{
		logMessage += "Error:" + e.getMessage();
		e.printStackTrace();
	}
	
	webClient.close();
	
	return true;
}
 
開發者ID:jiny2001,項目名稱:CVPR_paper_search_tool,代碼行數:36,代碼來源:Crawler.java

示例4: testUsesModel

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
@Test
public void testUsesModel() throws Exception {
    String path = webUrl + "jade?user=mvc%d";
    HtmlPage page = webClient.getPage(String.format(path, 0));
    assertTrue(page.getTitleText().contains("Jade"));
    for (int i = 0; i < 10; i++) { // just to ensure that not the whole page is cached
        page = webClient.getPage(String.format(path, i));
        HtmlHeading1 h1 = page.getFirstByXPath("//html/body/h1");
        assertTrue(h1.asText().contains("mvc" + i));
    }
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:12,代碼來源:JadeIT.java

示例5: testConfiguration

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
@Test
public void testConfiguration() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "jade/config");
    HtmlParagraph systemProperties = page.getFirstByXPath("//p[@class='SystemProperties']");
    assertEquals("SystemProperties", systemProperties.asText());
    HtmlParagraph configFile = page.getFirstByXPath("//p[@class='ConfigFile']");
    assertEquals("ConfigFile", configFile.asText());
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:9,代碼來源:JadeIT.java

示例6: login

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
public static boolean login(WebClient client, String userName,
		String passWrod) throws Exception {
	boolean flag = false;
	try {
		String s = "https://passport.sina.cn/signin/signin?entry=wapsso&vt=4&r=http%3A%2F%2Fmy.sina.cn%2F%3Fpos%3D108%26vt%3D4%26m%3D78fc51068140045a973a3aeab4db2381&amp;revalid=1";
		HtmlPage page = client.getPage(s);
		// <input type="text" placeholder="微博帳號/手機號/郵箱" autocorrect="off"
		// autocapitalize="off" id="loginName">

		HtmlInput htmlInput = page
				.getFirstByXPath("//input[@id='loginName']");
		htmlInput.click();
		htmlInput.setAttribute("value", userName);

		// <input type="password" placeholder="密碼" id="loginPassword">
		htmlInput = page.getFirstByXPath("//input[@id='loginPassword']");
		htmlInput.click();
		htmlInput.setAttribute("value", passWrod);

		// <a id="loginAction" class="btn_login" href="javascript:;">登錄</a>

		HtmlElement a = page.getFirstByXPath("//a[@id='loginAction']");
		page = a.click();

		client.setJavaScriptTimeout(5000);
		String str = page.asXml();
		if (!str.contains("QQ帳號登錄")) {
			flag = true;
			logger.error("登錄成功");
		}
	} catch (Exception e) {
		logger.error(e);
		flag = false;
	}
	return flag;
}
 
開發者ID:xiaomin0322,項目名稱:alimama,代碼行數:37,代碼來源:HtmlUnitUtil.java

示例7: fetchCourseName

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
public static String fetchCourseName(HtmlPage coursePage) {
    HtmlHeading1 filename = coursePage.getFirstByXPath(COURSE_NAME_XPATH);
    return clearCourseName(filename.asText());
}
 
開發者ID:theovier,項目名稱:lernplattform-crawler,代碼行數:5,代碼來源:GatewayCrawler.java

示例8: fetchFileName

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
private static String fetchFileName(HtmlPage currentPage) {
    HtmlHeading2 filename = currentPage.getFirstByXPath(FILENAME_XPATH);
    return cleanFileName(filename.asText());
}
 
開發者ID:theovier,項目名稱:lernplattform-crawler,代碼行數:5,代碼來源:DocumentCrawler.java

示例9: testIncludesViews

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
@Test
public void testIncludesViews() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "jade");
    HtmlParagraph footer = page.getFirstByXPath("//p[@class='footer']");
    assertTrue(footer.asText().contains("Ivar Grimstad"));
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:7,代碼來源:JadeIT.java

示例10: testUsesFilters

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
@Test
public void testUsesFilters() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "jade/markdown");
    HtmlUnorderedList ul = page.getFirstByXPath("//html/body/ul");
    assertEquals(3, ul.getChildElementCount());
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:7,代碼來源:JadeIT.java

示例11: testHelper

import com.gargoylesoftware.htmlunit.html.HtmlPage; //導入方法依賴的package包/類
@Test
public void testHelper() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "jade/helper");
    HtmlParagraph result = page.getFirstByXPath("//p[@class='result']");
    assertEquals("3", result.asText());
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:7,代碼來源:JadeIT.java


注:本文中的com.gargoylesoftware.htmlunit.html.HtmlPage.getFirstByXPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。