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


Java HtmlAnchor类代码示例

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


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

示例1: searchDuck

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

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
private static List<HtmlAnchor> login(final WebClient client)
		throws IOException, MalformedURLException, Exception {
	final HtmlPage homepage = client.getPage("http://ogame.org");

	// we use a POST because filling out the form and clicking the login button doesn't work...
	WebRequest settings = new WebRequest(new URL(
			"http://ogame.org/main/login"), HttpMethod.POST);

	settings.setRequestParameters(new ArrayList<NameValuePair>());
	settings.getRequestParameters().add(new NameValuePair("kid", ""));
	settings.getRequestParameters().add(new NameValuePair("uni", Main.settings.get("universe")));
	settings.getRequestParameters().add(new NameValuePair("login", Main.settings.get("login")));
	settings.getRequestParameters().add(new NameValuePair("pass", Main.settings.get("password")));

	page = client.getPage(settings);
	updateGame(page);

	List<HtmlAnchor> menu = (List<HtmlAnchor>)page.getByXPath("//a[contains(@class, 'menubutton')]");
	//System.out.println(menu);

	//dump(page, "game.html");
	return menu;
}
 
开发者ID:vcosta,项目名称:ogamemafia,代码行数:24,代码来源:Main.java

示例3: searchHouse

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
public void searchHouse() throws Exception {
	String url = "http://wx.fang.anjuke.com/loupan/?pi=baidu-cpcaf-wx-tyong2&utm_source=baidu&utm_medium=cpc&kwid=3367579001&utm_term=%E6%97%A0%E9%94%A1%E6%88%BF%E4%BA%A7%E7%BD%91";
	HtmlAnchor link = null;
	HtmlPage page = webClient.getPage(url);  
	
	//System.out.println(webClient.getCookies(new URL(url)));
	//System.out.println(page.asXml());
	List<HtmlAnchor> anchors = page.getAnchors();
	for(HtmlAnchor ha : anchors) {
		//System.out.println(ha.asXml());
		if(ha.asXml().indexOf("下一页") != -1) {
			link = ha;
			break;
		}
	}
	
	HtmlPage next = link.click();
	System.out.println(next.asXml());
}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:20,代码来源:PostDemo.java

示例4: execute

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void execute(Context context)
{
	LoggerFactory.getLogger(OpenLink.class).debug("Executing action: " + this);
	HtmlAnchor element = context.getXPathProcessor().getSingleElementOfType(Util.getCurrentPage(context), Util.replacePlaceholders(path, context), HtmlAnchor.class);

	try
	{
		element.click();
	}
	catch(IOException e)
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:sropelato,项目名称:Fetchino,代码行数:19,代码来源:OpenLink.java

示例5: getAllTvStationOfCity

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
/**
 * 抓取指定城市下的所有电视台
 * 
 * @param htmlPage
 * @param city
 * @return
 */
private List<TvStation> getAllTvStationOfCity(HtmlPage htmlPage, String city) {
	List<TvStation> resultList = new ArrayList<TvStation>();
	List<?> elements = htmlPage
			.getByXPath("//div[@class='chlsnav']//div[@class='plst']/parent::*");
	for (int i = 0, size = elements == null ? 0 : elements.size(); i < size; i++) {
		try {
			HtmlAnchor anchor = (HtmlAnchor) elements.get(i);
			String href = anchor.getHrefAttribute();
			if (!href.startsWith("/program/")) {
				continue;
			}
			logger.debug(anchor.getTextContent()
					+ " program table of tvmao: " + ", url: " + href);
			TimeUnit.MILLISECONDS.sleep(getRandomSleepTime());
			HtmlPage p = (HtmlPage) WebCrawler.crawl(TV_MAO_URL_PREFIX
					+ href);
			resultList.addAll(getTvStations(p, city));
		} catch (Exception e) {
			logger.error("error occur while get all tv station of city: "
					+ city, e);
			continue;
		}
	}
	return resultList;
}
 
开发者ID:52Jolynn,项目名称:MyTv,代码行数:33,代码来源:TvMaoCrawler.java

示例6: getCallbackUrl

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
@Override
protected String getCallbackUrl(HtmlPage authorizationPage) throws Exception {

    HtmlInlineFrame frame = (HtmlInlineFrame) authorizationPage.getElementById("ptlogin_iframe");
    // log.info("------------------------###\n{}------------------------===\n", authorizationPage.asXml());
    HtmlPage loginPage = (HtmlPage) frame.getEnclosedPage();

    log.info("------------------------###\n{}------------------------===\n", loginPage.getUrl().toString());

    HtmlAnchor passwordLogin = (HtmlAnchor) loginPage.getElementById("switcher_plogin");
    passwordLogin.click();

    HtmlForm loginForm = loginPage.getFormByName("loginform");
    loginForm.getInputByName("u").setValueAttribute(USER_QQ);
    loginForm.getInputByName("p").setValueAttribute(USER_PASSWORD);
    HtmlSubmitInput button = (HtmlSubmitInput) loginPage.getElementById("login_button");
    HtmlPage page2 = button.click();
    page2 = button.click();
    log.info(
            "------------------------###\n callbackUrl : {}------------------------===\n{}[email protected]@@@\n",
            page2.getUrl().toString(), page2.asXml());
    return page2.getUrl().toString();
}
 
开发者ID:btpka3,项目名称:pac4j-oauth-tencent,代码行数:24,代码来源:TestTencentClient.java

示例7: testUploadAndDownloadAttachment

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
public void testUploadAndDownloadAttachment() throws Exception {
  String name = uniqueWikiPageName("AttachmentsTest");
  HtmlPage page = editWikiPage(name, "Content", "", "", true);
  HtmlPage attachments = uploadAttachment(ATTACHMENT_UPLOAD_FILE_1, name);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(attachments, "file.txt")));

  // A link should have been added to the page.
  page = getWikiPage(name);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(page, "/attachments/file.txt")));

  attachments = clickAttachmentsLink(page, name);
  HtmlForm form = attachments.getFormByName("replaceAttachmentUpload");
  form.getInputByName("file").setValueAttribute(ATTACHMENT_UPLOAD_FILE_2);
  attachments = (HtmlPage) form.getInputByValue("Upload").click();
  assertEquals("File 2.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(page, "/attachments/file.txt")));

  HtmlAnchor previousRevision = (HtmlAnchor) attachments.getByXPath("//a[contains(@href, '?revision')]").get(0);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(previousRevision));
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:20,代码来源:TestAttachments.java

示例8: testUploadAndDeleteAttachment

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
public void testUploadAndDeleteAttachment() throws Exception {
  String name = uniqueWikiPageName("AttachmentsTest");
  HtmlPage page = editWikiPage(name, "Content", "", "", true);
  HtmlPage attachments = uploadAttachment(ATTACHMENT_UPLOAD_FILE_1, name);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(getAnchorByHrefContains(attachments, "file.txt")));

  page = getWikiPage(name);
  attachments = clickAttachmentsLink(page, name);
  HtmlForm deleteForm = attachments.getFormByName("deleteAttachment");
  attachments = deleteForm.getButtonByName("delete").click();

  // There shouldn't be any link directly to the attachment
  for(Object o: attachments.getByXPath("//a[contains(@href, 'file.txt')]")) {
    HtmlAnchor anchor = (HtmlAnchor) o;
    assertEquals(true, anchor.getHrefAttribute().contains("?revision"));
  }

  // Previous version should still be available
  HtmlAnchor previousRevision = (HtmlAnchor) attachments.getByXPath("//a[contains(@href, '?revision')]").get(0);
  assertEquals("File 1.", getTextAttachmentAtEndOfLink(previousRevision));
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:22,代码来源:TestAttachments.java

示例9: extractData

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
public Collection<DataRecord> extractData(String url, Page page) {
    DataRecord record = new DataRecord(url, RECORD_TYPE);
    try {
        if (page.isHtmlPage()) {
            List<HtmlAnchor> anchors = ((HtmlPage) page).getAnchors();
            if (anchors != null) {
                int count = 0;
                for (HtmlAnchor anchor : anchors) {
                    record.setField(FIELD_PREFIX + count, anchor.getHrefAttribute());
                    count++;
                }
            }
        }
    } catch (Exception e) {
        logger.error("Could not parse page", e);
    }
    return Arrays.asList(record);
}
 
开发者ID:cfagiani,项目名称:datasponge,代码行数:19,代码来源:HyperlinkExtractor.java

示例10: main

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
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();		
	
	
}
 
开发者ID:swz887799,项目名称:Crawler_Self_Analysis,代码行数:22,代码来源:ApiUse.java

示例11: create

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
/**
 * 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();  
}
 
开发者ID:jkjoschua,项目名称:poe-ladder-tracker-java,代码行数:17,代码来源:CSVLinkCreator.java

示例12: deletePost

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
public boolean deletePost(PostObject post){
	conn = new WebConnection();
	
	String deleteUrl = post.getUrl();
	
	try {
		conn.connect(deleteUrl);
		if(conn.login()){
			conn.connect(deleteUrl);
			WebPageManipulation pageManipulation = new WebPageManipulation(conn.getStartPage());
			
			List<HtmlAnchor> deleteLink = (List<HtmlAnchor>) pageManipulation.getByXPath("//a[@class='submitdelete deletion']");
			
			HtmlPage redirect = deleteLink.get(0).click();
			
			if(redirect.toString().contains("trashed=1") && redirect.toString().contains("ids="+post.getId())){
				return true;
			}else{
				return false;
			}
		}
	}catch(Exception e){
		e.printStackTrace();
	}
	
	return false;		
}
 
开发者ID:klevinism,项目名称:Ads-Attacher,代码行数:28,代码来源:AsyncTasks.java

示例13: searchInBaidu

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
public void searchInBaidu() throws Exception {
	HtmlPage page = webClient.getPage("https://www.baidu.com/");  
	HtmlForm form = page.getFormByName("f");
	
	HtmlTextInput input = form.getInputByName("wd");	
	HtmlSubmitInput button = form.getInputByValue("百度一下");  
	
	input.setValueAttribute("无锡");
	HtmlPage nextPage = button.click();  
	
	//System.out.println(nextPage.asXml());
	
	// hit next page
	HtmlAnchor next = null;
	List list = nextPage.getByXPath("//a");
	for(Object obj : list) {
		if(obj instanceof HtmlAnchor) {
			HtmlAnchor ha = (HtmlAnchor)obj;
			//System.out.println(ha.getTextContent());
			if(ha.getTextContent().indexOf("百度百科") != -1) {
				next = ha;
				break;
			}
		}
	}
	
	
	System.out.println(next.asXml());
	System.out.println("--------------------------");
	HtmlPage p = next.click();
	System.out.println(p.asXml());
	
}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:34,代码来源:PostDemo.java

示例14: shouldOwnerIndexPageNavigateToOwnerDetailPage

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
@Test
public void shouldOwnerIndexPageNavigateToOwnerDetailPage() throws Exception {
  HtmlPage ownerIndexPage = getPage("/owners");
  List viewEditDeleteButtons = ownerIndexPage.getByXPath("//tbody/tr[1]/td[6]//a");
  HtmlAnchor aHref = (HtmlAnchor) viewEditDeleteButtons.get(0);
  HtmlPage viewOwnerPage = aHref.click();
  assertTrue(viewOwnerPage.getUrl().toString().matches(".*/owners/1$"));
}
 
开发者ID:puncha,项目名称:petclinic,代码行数:9,代码来源:OwnerControllerTests.java

示例15: testLogin

import com.gargoylesoftware.htmlunit.html.HtmlAnchor; //导入依赖的package包/类
@Test
public void testLogin() {
	weiWS.loginIfNecessary();
	URL url = weiWS.getCurrentPage().getUrl();
	System.out.println(url.toString());
	url = weiWS.getCurrentPage().getBaseURL();
	System.out.println(url.toString());
	//
	Set<Cookie> cookies = weiWS.getInstance().getCookieManager().getCookies();
	Assert.assertFalse(cookies.isEmpty());
	for (Cookie cookie : cookies) {
		System.out.println(cookie.toString());
	}
	//
	HtmlAnchor logout = (HtmlAnchor) weiWS.getCurrentPage().getElementById("logout");
	Assert.assertNotNull(logout);
	//
	IdentityUnit unit = weiWS.lookup(WeixinmpWebSession.IDENTITY_UNIT_KEY);

	Assert.assertNotNull(unit);
	System.out.println(unit);
	Assert.assertEquals(weiWS.getSecurityNP().getName(), unit.getUserName());

	Assert.assertNotNull(unit.getAccessToken());

	Assert.assertNotNull(unit.getSessionId());
}
 
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:28,代码来源:WeixinmpWebSessionTest.java


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