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


Java Element.absUrl方法代碼示例

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


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

示例1: doInBackground

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
protected Void doInBackground(final Void... voids) {

    final Document document;
    try {
        document = Jsoup.connect(PUBG_NEWS_LINK).get();
        for (final Element row : document.select(NEWS_DOCUMENT_SELECTOR)) {
            final String title = row.select(NEWS_TITLE_SELECTOR).text();
            final String type = row.select(NEWS_TYPE_SELECTOR).text();
            final String date = row.select(NEWS_DATE_SELECTOR).text();
            final String description = row.select(NEWS_DESCRIPTION_SELECTOR).text();
            final Element link = row.select(NEWS_LINK_SELECTOR).first();
            final String linkSrc = link.absUrl(NEWS_LINKSRC_SELECTOR);
            final Element img = row.select(NEWS_IMG_SELECTOR).first();
            final String imgSrc = img.absUrl(NEWS_IMGSRC_SELECTOR);

            publishProgress(new NewsItem(title, type, date, description, linkSrc, imgSrc));
        }
    } catch(IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:ZafraniTechLLC,項目名稱:Companion-For-PUBG-Android,代碼行數:24,代碼來源:PUBGNewsFetch.java

示例2: handle

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public void handle(boolean allAttr, String attrKey, Element element, List<SIPNode> ret) {
    if (allAttr) {
        for (Attribute attribute : element.attributes()) {
            ret.add(SIPNode.t(element.absUrl(attribute.getKey())));
        }
    } else {
        String value = element.absUrl(attrKey);
        if (StringUtils.isNotBlank(value)) {
            ret.add(SIPNode.t(value));
        }
    }
}
 
開發者ID:virjar,項目名稱:sipsoup,代碼行數:14,代碼來源:AbsUrlFunction.java

示例3: getURLsFromPageStatic

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private static List<String> getURLsFromPageStatic(Document doc) {
     List<String> imageURLs = new ArrayList<>();
     Elements els = doc.select("#ContentPlaceHolder1_divContent");
     Elements imgs = els.select("img");
     for (Element img : imgs) {
         String src = img.absUrl("src");
         src = src.replaceAll("_[a-zA-Z]{3,5}", "");

         if (!src.equals("")) {
             imageURLs.add(src);
         }
     }
     return imageURLs;
}
 
開發者ID:RipMeApp,項目名稱:ripme,代碼行數:15,代碼來源:VidbleRipper.java

示例4: action

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public void action(String[] args, GuildMessageReceivedEvent event) throws ParseException, IOException {
    if (args.length < 1) {event.getChannel().sendMessage(help()); return;}
    String query = "";
    for(int i = 0; i < args.length; i++){
        query += " " + args[i];
    }
    String google = "http://www.google.com/search?q=";
    String search = query;
    String charset = "UTF-8";
    String userAgent = "Amme 7.5 (+http://lordlee.de)";

    Elements links = Jsoup.connect(google + URLEncoder.encode(search, charset)).userAgent(userAgent).get().select(".g>.r>a");

    for (Element link : links) {
        String title = link.text();
        String url = link.absUrl("href"); // Google returns URLs in format "http://www.google.com/url?q=<url>&sa=U&ei=<someKey>".
        url = URLDecoder.decode(url.substring(url.indexOf('=') + 1, url.indexOf('&')), "UTF-8");

        if (!url.startsWith("http")) {
            continue; // Ads/news/etc.
        }

        ttemp = ttemp + link.text().toString() + link.baseUri() +  "\n";

    }
    util.embedSender.sendEmbed("Search Results for **" + query + "**:\n" + ttemp,event.getChannel(), Color.GREEN);
}
 
開發者ID:LeeDJD,項目名稱:Amme,代碼行數:29,代碼來源:google.java

示例5: url2xhtml

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
/**
 * 將頁麵轉為{@link org.jsoup.nodes.Document}對象,xhtml 格式
 *
 * @param url
 * @return
 * @throws Exception
 */
protected Document url2xhtml(String url) throws Exception {
    Document doc = Jsoup.connect(url).get(); //獲得

    if (logger.isDebugEnabled()) {
        logger.debug("baseUri: {}", doc.baseUri());
    }

    for (Element script : doc.getElementsByTag("script")) { //除去所有 script
        script.remove();
    }

    for (Element a : doc.getElementsByTag("a")) { //除去 a 的 onclick,href 屬性
        a.removeAttr("onclick");
        a.removeAttr("href");
    }

    Elements links = doc.getElementsByTag("link"); //將link中的地址替換為絕對地址
    for (Element element : links) {
        String href = element.absUrl("href");

        if (logger.isDebugEnabled()) {
            logger.debug("href: {} -> {}", element.attr("href"), href);
        }

        element.attr("href", href);
    }

    doc.outputSettings()
            .syntax(Document.OutputSettings.Syntax.xml)
            .escapeMode(Entities.EscapeMode.xhtml);  //轉為 xhtml 格式

    if (logger.isDebugEnabled()) {
        String[] split = doc.html().split("\n");
        for (int c = 0; c < split.length; c++) {
            logger.debug("line {}:\t{}", c + 1, split[c]);
        }
    }
    return doc;
}
 
開發者ID:vindell,項目名稱:docx4j-template,代碼行數:47,代碼來源:HtmlConverter.java

示例6: parse

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
public Link parse() throws IOException {
    Link parent = null;

    do {
        visited.add(startUrl);

        Connection con = Jsoup.connect(startUrl).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");
        Document doc = con.get();

        Element head = doc.getElementById("firstHeading");
        Link current = new Link(startUrl, head.text());

        current.parent = parent;
        parent = current;

        Elements links = doc.getElementById("bodyContent").select("a[href]");

        for(Element link : links) {
            String url = link.absUrl("href");

            if(url.startsWith("https://en.wikipedia.org/wiki/") && url.lastIndexOf(":") == 5 && !url.contains("#")) {
                if(url.equals("https://en.wikipedia.org/wiki/Philosophy")) {
                    Link phil = new Link("https://en.wikipedia.org/wiki/Philosophy", "Philosophy");
                    phil.parent = parent;

                    return phil;
                }

                if(!visited.contains(url))
                    toVisit.add(url);
            }
        }

        startUrl = toVisit.poll();
    } while(!toVisit.isEmpty());

    return null;
}
 
開發者ID:nikmanG,項目名稱:DailyProgrammer,代碼行數:39,代碼來源:WebParser.java

示例7: crawlQuoraPage

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private void crawlQuoraPage(String url, boolean crawlRelated) {
	// log("crawling for Quora url : " + url);
	uniqueQuoraLinks.add(url);
	Document doc = getDocument(url);
	if (doc == null) {
		// log("document is null for quora url: " + url);
		return;
	}

	Elements statsElements = doc.select("div.QuestionStats");
	for (Element statsElement : statsElements) {
		System.out.print(count++ + "\t" + url);
		Elements statsElementValues = statsElement.getElementsByTag("strong");
		int i = 1;
		for (Element statsElementValue : statsElementValues) {
			if (i > 2) {
				break;
			}
			System.out.print("\t" + statsElementValue.getElementsByTag("strong").text());
			i++;
		}
	}

	Elements activityElements = doc.getElementsByClass("QuestionLastActivityTime");
	if (activityElements.size() > 0) {
		for (Element activityElement : activityElements) {
			String lastAsked = StringUtils.remove(activityElement.text(), "Last asked: ");
			if (!lastAsked.contains("201")) {
				lastAsked = lastAsked + ", 2016";
			}
			System.out.println("\t" + lastAsked);
		}
	} else {
		System.out.println();
	}

	if (crawlRelated) {
		// log("crawlRelated is true for : " + url);
		Elements relatedQuestions = doc.getElementsByClass("question_related");
		List<Element> relatedQuestionList = new ArrayList<>();
		for (Element relatedQuestion : relatedQuestions) {
			Elements relatedQuestionHrefs = relatedQuestion.select("a[href]");
			for (Element element : relatedQuestionHrefs) {
				relatedQuestionList.add(element);
			}
		}

		relatedQuestionList = Utils.getSublist(relatedQuestionList, QuoraConstants.numReLatedQuestion);
		for (Element relatedQuestionHref : relatedQuestionList) {
			String relatedUrl = relatedQuestionHref.absUrl("href");
			if (!uniqueQuoraLinks.contains(relatedUrl)) {
				crawlQuoraPage(relatedUrl, false);
			}
		}

	}
}
 
開發者ID:thekosmix,項目名稱:Quora-Marketing,代碼行數:58,代碼來源:QuoraCrawler.java


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