当前位置: 首页>>代码示例>>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;未经允许,请勿转载。