本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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());
}
示例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&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;
}
示例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());
}
示例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());
}
示例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"));
}
示例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());
}
示例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());
}