示例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本文标签属性:
示例:示例是什么意思
代码:代码是什么
java:java游戏