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


Java Element.getElementsByTag方法代码示例

本文整理汇总了Java中org.jsoup.nodes.Element.getElementsByTag方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getElementsByTag方法的具体用法?Java Element.getElementsByTag怎么用?Java Element.getElementsByTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.nodes.Element的用法示例。


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

示例1: parseCollectionsRepositoryData

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private Repository parseCollectionsRepositoryData(Element element) throws Exception{
    String fullName = element.select("div > div > a").attr("href");
    String owner = fullName.substring(1, fullName.lastIndexOf("/"));
    String repoName = fullName.substring(fullName.lastIndexOf("/") + 1);
    String ownerAvatar = element.select("div > div > a > img").attr("src");

    Elements articleElements = element.getElementsByTag("div");
    Element descElement = articleElements.get(articleElements.size() - 2);
    StringBuilder desc = new StringBuilder("");
    for(TextNode textNode : descElement.textNodes()){
        desc.append(textNode.getWholeText());
    }

    Element numElement = articleElements.last();
    String starNumStr =  numElement.select("a").get(0).textNodes().get(1).toString();
    String forkNumStr =  numElement.select("a").get(1).textNodes().get(1).toString();
    String language = "";
    Elements languageElements = numElement.select("span > span");
    if(languageElements.size() > 0){
        language = numElement.select("span > span").get(1).textNodes().get(0).toString();
    }

    Repository repo = new Repository();
    repo.setFullName(fullName);
    repo.setName(repoName);
    User user = new User();
    user.setLogin(owner);
    user.setAvatarUrl(ownerAvatar);
    repo.setOwner(user);

    repo.setDescription(desc.toString());
    repo.setStargazersCount(Integer.parseInt(starNumStr.replaceAll(" ", "")));
    repo.setForksCount(Integer.parseInt(forkNumStr.replaceAll(" ", "")));
    repo.setLanguage(language);

    return repo;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:38,代码来源:RepositoriesPresenter.java

示例2: parseDateStatesMap

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static Map<Integer, String> parseDateStatesMap(String html) {
    int i = html.indexOf("<table id=\"calendar\"");
    if(i == -1)
        return null;
    int j = html.indexOf("</table>", i);
    Document document = JsoupDocumentUtils.parseUTF8HTMLDocument(html.substring(i, j + "</table>".length()));
    Element table = document.getElementById("calendar");
    Elements tds = table.getElementsByTag("td");
    Map<Integer, String> map = new HashMap<Integer, String>();
    int date = 1;
    for(Iterator<Element> iter = tds.iterator(); iter.hasNext(); ) {
        Element td = iter.next();
        Element child = td.children().first();
        if(child != null) {
            String className = child.className();
            if(!className.isEmpty()) {
                map.put(date++, className);
            }
        }
    }
    return map;
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:23,代码来源:AppointmentParser.java

示例3: parseSearchTestCenters

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static List<Map<String, Object>> parseSearchTestCenters(String html) {
    int i = html.indexOf("<table id=\"apptable\"");
    if(i == -1)
        return null;
    int j = html.indexOf("</table>", i);
    Document document = JsoupDocumentUtils.parseUTF8HTMLDocument(html.substring(i, j + "</table>".length()));
    Element table = document.getElementsByTag("tbody").get(0);
    Elements trs = table.getElementsByTag("tr");
    List<Map<String, Object>> testCenterList = new ArrayList<Map<String, Object>>();
    for(Iterator<Element> iter = trs.iterator(); iter.hasNext(); ) {
        Elements tds = iter.next().getElementsByTag("td");
        Map<String, Object> testCenter = new HashMap<String, Object>();
        testCenter.put("centerID", Long.valueOf(tds.get(0).attr("id").substring(1)));
        testCenter.put("name", tds.get(2).text());
        testCenter.put("distance", tds.get(4).html().replaceAll("&nbsp;", "").trim());
        testCenter.put("city", tds.get(5).text().trim());
        testCenter.put("state", tds.get(6).html().replaceAll("&nbsp;", "").trim());
        testCenter.put("country", tds.get(7).text().trim());
        testCenterList.add(testCenter);
    }
    return testCenterList;
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:23,代码来源:AppointmentParser.java

示例4: parseAppointmentTestCenters

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static List<Map<String, Object>> parseAppointmentTestCenters(String html) {
    int i = html.indexOf("<div id=\"choosecenter\"");
    if(i == -1)
        return null;
    int j = html.indexOf("</div>", i);
    Document document = JsoupDocumentUtils.parseUTF8HTMLDocument(html.substring(i, j + "</div>".length()));
    Element table = document.getElementsByTag("table").get(0);
    Elements trs = table.getElementsByTag("tr");
    List<Map<String, Object>> testCenterList = new ArrayList<Map<String, Object>>();
    for(Iterator<Element> iter = trs.iterator(); iter.hasNext(); ) {
        Elements tds = iter.next().getElementsByTag("td");
        Map<String, Object> testCenter = new HashMap<String, Object>();
        Matcher m = Pattern.compile("\"(\\d+)\"").matcher(tds.get(0).child(0).attr("onclick"));
        m.find();
        testCenter.put("centerID", Long.parseLong(m.group(1)));
        testCenter.put("info", tds.get(1).text());
        testCenterList.add(testCenter);
    }
    return testCenterList;
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:21,代码来源:AppointmentParser.java

示例5: parseExams

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static List<Map<String, Object>> parseExams(String html) {
    int i = html.indexOf("<table cellspacing=\"0\" id=\"apptable\">");
    if(i == -1)
        return null;
    int j = html.indexOf("</table>", i);
    Document document = JsoupDocumentUtils.parseUTF8HTMLDocument(html.substring(i, j + "</table>".length()));
    Element table = document.getElementsByTag("tbody").get(0);
    Elements trs = table.getElementsByTag("tr");
    List<Map<String, Object>> examList = new ArrayList<Map<String, Object>>();
    for(Iterator<Element> iter = trs.iterator(); iter.hasNext(); ) {
        Elements tds = iter.next().getElementsByTag("td");
        Map<String, Object> exam = new HashMap<String, Object>();
        Matcher m = Pattern.compile("'\\S+examSeriesID=(\\d+)';").matcher(tds.get(0).child(0).attr("onclick"));
        m.find();
        exam.put("examSeriesID", Long.valueOf(m.group(1)));
        exam.put("code", tds.get(1).text());
        exam.put("name", tds.get(3).text());
        examList.add(exam);
    }
    return examList;
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:22,代码来源:AppointmentParser.java

示例6: getResourceArrayMap

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
protected Map<String, List<String>> getResourceArrayMap(String tag) {
    Map<String, List<String>> map = new HashMap<>();

    Document document = getValuesXmlDocument();
    Elements elements = document.getElementsByTag(tag);

    for (Element element : elements) {
        Elements items = element.getElementsByTag("item");

        List<String> itemsText = new ArrayList<>();

        for (Element item : items) {
            String text = ((TextNode) item.childNode(0)).text();

            itemsText.add(text);
        }

        String name = element.attr("name");
        map.put(name, itemsText);
    }
    return map;
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:23,代码来源:ShadowResources.java

示例7: getRawData

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static String[][] getRawData(Document doc){
    String[][] rawData = new String[doc.getElementsByTag("tr").size()][];
    int j = 0;
    for (Element curr : doc.getElementsByTag("tr")) {
        int i = 0;
        rawData[j] = new String[curr.getElementsByTag("td").size() - 2];//one of the 2 base cases
        for (Element info : curr.getElementsByTag("td")) {
            if(info.text().equals("Add")) continue;
            if(info.text().matches("\\(\\d+\\)")) continue;//number between parenthesis, the ratings
            rawData[j][i] = info.text();
            i++;
        }
        j++;
    }
    return rawData;
}
 
开发者ID:asdiamond,项目名称:CodeMineProject1,代码行数:17,代码来源:PartPickerScraper.java

示例8: getClub

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public ClubType getClub() throws Exception {
    Element root = document.getElementsByClass("profile-header-top").first();
    Element topPart = root.getElementsByClass("header-title").first();
    Elements bc = topPart.getElementsByTag("span");
    if (bc.size() == 0) {
        return ClubType.NONE;
    }
    String bcType = bc.first().className();
    if (bcType.equalsIgnoreCase("icon-bc")) {
        return ClubType.CLASSIC;
    }
    if (bcType.equalsIgnoreCase("icon-tbc")) {
        return ClubType.TURBO;
    }
    return ClubType.OUTRAGEOUS;
}
 
开发者ID:PizzaCrust,项目名称:Roblox4j,代码行数:18,代码来源:BasicRobloxian.java

示例9: parseZhihuTopics

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static void parseZhihuTopics(Page page, Result result){
    String html = page.getContent();
    Document doc = Jsoup.parse(html);
    Element zmTopicCatMainUl = doc.body().select("div.zg-wrap.zu-main.clearfix").first().select("ul.zm-topic-cat-main.clearfix").first();
    Elements lis = zmTopicCatMainUl.getElementsByTag("li");
    for(Element element : lis){
        String topicId = element.attr("data-id");
        Request request = new Request("https://www.zhihu.com/node/TopicsPlazzaListV2", HttpMethod.POST);
        JSONObject object = new JSONObject();
        object.put("topic_id",Integer.parseInt(topicId));
        object.put("offset",0);
        object.put("hash_id","22e50cd21ed9df7085ff76d62175e986");
        request.addParame("method","next")
                .addParame("params",object.toJSONString()).addAttach("offset",Integer.valueOf(0)).addAttach("topic_id",Integer.parseInt(topicId));
        result.addRequest(request);
    }
}
 
开发者ID:StevenKin,项目名称:ZhihuQuestionsSpider,代码行数:18,代码来源:ParseRegularUtil.java

示例10: parse

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public List<Proxy> parse(String html) {
    Document document = Jsoup.parse(html);
    Elements elements = document.select("table > tbody > tr");
    List<Proxy> proxyList = new LinkedList<>();
    for (int i = 0; i < elements.size(); i++) {
        if (i == 0) {
            continue;
        }
        Element element = elements.get(i);
        Elements tds = element.getElementsByTag("td");
        Proxy proxy = new Proxy();
        proxyList.add(proxy);
        proxy.setIp(tds.get(0).ownText());
        proxy.setPort(NumberUtils.toInt(tds.get(1).ownText()));
        proxy.setAnonymity(tds.get(2).ownText());
        proxy.setProtocol(tds.get(3).ownText());
        proxy.setSpeed(tds.get(4).ownText());
        proxy.setSource(tds.get(5).ownText());
        Pattern compile = Pattern.compile("(\\d+)分钟");
        Matcher matcher = compile.matcher(tds.get(6).ownText());
        if (matcher.find()) {
            String group = matcher.group(1);
            DateTime time = DateTime.now().minusMinutes(NumberUtils.toInt(group));
            proxy.setUpdateTime(time.toDate());
        }
    }
    return proxyList;
}
 
开发者ID:jt120,项目名称:take,代码行数:30,代码来源:IP181ProxyParser.java

示例11: getURLs

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static List<URL> getURLs(URL url) throws IOException{

        Response resp = Http.url(url)
                            .ignoreContentType()
                            .response();

        Document doc = resp.parse();

        List<URL> URLs = new ArrayList<>();
        //Pictures
        Elements imgs = doc.getElementsByTag("img");
        for (Element img : imgs) {
            if (img.hasClass("album-image")) {
                String imageURL = img.attr("src");
                imageURL = "https:" + imageURL;
                URLs.add(new URL(imageURL));
            }
        }
        //Videos
        Elements vids = doc.getElementsByTag("video");
        for (Element vid : vids) {
            if (vid.hasClass("album-video")) {
                Elements source = vid.getElementsByTag("source");
                String videoURL = source.first().attr("src");
                URLs.add(new URL("https:" + videoURL));
            }
        }

        return URLs;
    }
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:31,代码来源:EroShareRipper.java

示例12: getURLs

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static List<URL> getURLs(URL url) throws IOException{

        Response resp = Http.url(url)
                            .ignoreContentType()
                            .response();

        Document doc = resp.parse();

        List<URL> URLs = new ArrayList<>();
        //Pictures
        Elements imgs = doc.getElementsByTag("img");
        for (Element img : imgs) {
            if (img.hasClass("album-image")) {
                String imageURL = img.attr("src");
                imageURL = "https:" + imageURL;
                URLs.add(new URL(imageURL));
            }
        }
        //Videos
        Elements vids = doc.getElementsByTag("video");
        for (Element vid : vids) {
            if (vid.hasClass("album-video")) {
                Elements source = vid.getElementsByTag("source");
                String videoURL = source.first().attr("src");
                URLs.add(new URL(videoURL));
            }
        }

        return URLs;
    }
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:31,代码来源:EromeRipper.java

示例13: print2

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private void print2(String baseLocation) throws IOException, TransformerException, ParserConfigurationException {
        Document document = Jsoup.connect(baseLocation).get();
        Elements content = document.getElementsByAttributeValue("class", "entry-content");
        String title = null;
        ArrayList<String> list = new ArrayList<>();
        for (Element div : content) {
            List<Node> nodes = div.childNodes();
            for (Node node : nodes) {
                if (node instanceof Element) {
                    if (((Element) node).tagName().equals("h3")) {
                        writeFile(title, list);
                        list.clear();
                        System.out.println("Title: " + node.childNode(0));
                        title = node.childNode(0).toString();
                    } else if (((Element) node).tagName().equals("table")) {
                        //print table
                        Elements tr = ((Element) node).getElementsByTag("tr");
                        for (Element element : tr) {
                            Elements td = element.getElementsByTag("td");
                            for (Element value : td) {
                                if (value.childNodeSize() > 0) {
                                    if (!(value.childNode(0) instanceof Comment)) {
//                                        System.out.println("Emoticon: " + value.childNode(0) + " " + value.childNode(0).getClass().getSimpleName());
                                        list.add(value.childNode(0).toString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
 
开发者ID:tranleduy2000,项目名称:ascii_generate,代码行数:34,代码来源:GetEmoticons.java

示例14: parse

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
 * @param lunchguiden a Lunchguiden jsoup Document
 * @return list of restaurants and their schnitzel dishes of the day
 */
List<Restaurant> parse(Document lunchguiden) {

	List<Restaurant> restaurants = new ArrayList<Restaurant>(0);

	// TODO: Convert to Java 8 Lambdas?
	for (Element restaurantElement : lunchguiden.getElementById("restaurants").getElementsByClass("restaurant")) {
		Element menuElement = restaurantElement.getElementsByClass("restaurant_menu").get(0);

		if (StringUtils.containsIgnoreCase(menuElement.toString(), "schnitzel")) {

			final Restaurant restaurant = new Restaurant();
			restaurant.setId(restaurantElement.id());
			restaurant.setName(restaurantElement.getElementsByClass("header_left").get(0).text());

			LOG.info("Setting up {}", restaurant.getName());

			List<String> dishes = new ArrayList<String>(0);

			for (Element menuItem : menuElement.getElementsByTag("li")) {

				// TODO: Use fuzzy searching in case "schnitzel" is misspelled in the menu?
				// See https://en.wikipedia.org/wiki/Approximate_string_matching

				if (StringUtils.containsIgnoreCase(menuItem.toString(), "schnitzel")) {
					dishes.add(menuItem.text());
					LOG.info("Adding \"{}\" to {}", menuItem.text(), restaurant.getName());
				}
			}

			restaurant.setDishes(dishes);
			restaurants.add(restaurant);

		}
	}
	return restaurants;
}
 
开发者ID:pheimdah,项目名称:schnitzel.ax,代码行数:41,代码来源:LunchguidenRepository.java

示例15: postDataSave

import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private void postDataSave(int category) throws Exception{
	String url = PostParser.getUrlFromCategory(category);
	int page = 1;
	int count = 0;
	while (true) {
		Document doc = ParserUtils.getDoc(ParserUtils.getUrl(url, page++));
		Element body = doc.getElementsByTag("tbody").get(0);
		Elements elements = body.getElementsByTag("tr");
		if (elements.size() == 1)
			break;
		for (int i = 1; i < elements.size(); i++) {
			Element element = elements.get(i);
			int postNum = Integer.valueOf(element.getElementsByTag("td").get(0).text());
			if (!check(category, postNum)) {
				String onClick = element.getElementsByTag("a").get(0).attr("onclick");
				Pattern pattern = Pattern.compile("'([a-zA-Z0-9]*)'");
				Matcher matcher = pattern.matcher(onClick);
				List<String> list = new ArrayList<String>();
				while(matcher.find()){
					list.add(matcher.group(0).replaceAll("'", ""));
				}
				PostParser parser = new PostParser(category, postNum, list.toArray());
				parser.parse();
				count++;
			}
		}
	}
	if (count > 0)
		Log.l(QueryUtils.queryBuilder(categoryToString(category), " finish parse count : ", count));
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:31,代码来源:PostChangeDetector.java


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