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


Java Element类代码示例

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


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

示例1: populatePointsGivenToRB

import org.jsoup.nodes.Element; //导入依赖的package包/类
public void populatePointsGivenToRB(Team team) {
	int rankCounter = 0;
 		Element rbPointsAllowedTable = rbPointsAllowedURL.select("table").get(1);
 	    Elements rbPointsAllowedRows = rbPointsAllowedTable.select("tr");
 	    
 	    for (int i = 2; i < rbPointsAllowedRows.size(); i++) {
 	    		Element row = rbPointsAllowedRows.get(i);
 	    		Elements cols = row.select("td");
 	    		rankCounter++;
     		
 	    		if(cols.get(0).text().contains(team.getName())) {
 	    			if (cols.get(2).text().contains("*")) {
    				team.setFpToRBRank(rankCounter);
	    			team.setFpToRBAvg(Double.parseDouble(cols.get(18).text()));
	    			break;
    			} else {
	    			team.setFpToRBRank(rankCounter);
	    			team.setFpToRBAvg(Double.parseDouble(cols.get(19).text()));
	    			break;
	    		}
 	    		}
 	    }
}
 
开发者ID:lucci,项目名称:NFLFantasyAnalyzer,代码行数:24,代码来源:WebScraper.java

示例2: parseProxys

import org.jsoup.nodes.Element; //导入依赖的package包/类
@Override
public List<Proxy> parseProxys(String content) {
    Document doc = Jsoup.parse(content);
    Elements elements = doc.select("div#list table tbody tr");
    List<Proxy> proxyList = new ArrayList<>();
    for(Element tr : elements){
        Elements tds = tr.children();
        String ip = tds.get(0).text().trim();
        Integer port = Integer.parseInt(tds.get(1).text());
        proxyList.add(new Proxy(ip,port));
    }
    return proxyList;
}
 
开发者ID:StevenKin,项目名称:ZhihuQuestionsSpider,代码行数:14,代码来源:KuaidailiProxySite.java

示例3: leagueStatusCheck

import org.jsoup.nodes.Element; //导入依赖的package包/类
@Test
public void leagueStatusCheck() throws Exception {
    Document doc = Jsoup.connect("http://www.espn.com/wnba/scoreboard/_/group/50")
            .timeout(60 * 1000)
            .maxBodySize(0)
            .get();
    Elements scriptElements = doc.getElementsByTag("script");
    Pattern pattern = Pattern.compile("window.espn.scoreboardData[\\s\t]*= (.*);.*window.espn.scoreboardSettings.*");
    for (Element element : scriptElements) {
        for (DataNode node : element.dataNodes()) {
            if (node.getWholeData().startsWith("window.espn.scoreboardData")) {
                Matcher matcher = pattern.matcher(node.getWholeData());
                if (matcher.matches()) {
                    Gson gson = new Gson();
                    EspnJson espnJson = new Gson().fromJson(matcher.group(1), EspnJson.class);
                    System.out.println(espnJson.getTeams());
                    assertEquals(false, espnJson.getTeams().isEmpty());
                }
            }
        }
    }
}
 
开发者ID:riteshakya037,项目名称:Android-Scrapper,代码行数:23,代码来源:ExampleUnitTest.java

示例4: GetDivContent

import org.jsoup.nodes.Element; //导入依赖的package包/类
private static String GetDivContent(Element div) {
    StringBuilder sb = new StringBuilder();
    //考虑div里标签内容的顺序,对div子树进行深度优先搜索
    Stack<Element> sk = new Stack<Element>();
    sk.push(div);
    while (!sk.empty()) {
        //
        Element e = sk.pop();
        //对于div中的div过滤掉
        if (e != div && e.tagName().equals("div")) continue;
        //考虑正文被包含在p标签中的情况,并且p标签里不能含有a标签
        if (e.tagName().equals("p") && e.getElementsByTag("a").size() == 0) {
            String className = e.className();
            if (className.length() != 0 && className.equals("pictext")) continue;
            sb.append(e.text());
            sb.append("\n");
            continue;
        } else if (e.tagName().equals("td")) {
            //考虑正文被包含在td标签中的情况
            if (e.getElementsByTag("div").size() != 0) continue;
            sb.append(e.text());
            sb.append("\n");
            continue;

        }
        //将孩子节点加入栈中
        Elements children = e.children();
        for (int i = children.size() - 1; i >= 0; i--) {
            sk.push((Element) children.get(i));
        }
    }

    return sb.toString();
}
 
开发者ID:xjtushilei,项目名称:ScriptSpider,代码行数:35,代码来源:ContentExtractor.java

示例5: takeDailyPick

import org.jsoup.nodes.Element; //导入依赖的package包/类
/**
 * 每日推荐
 *
 * @param str
 */
public List<IHistoryDailyPicks> takeDailyPick(String str) {
    Document document = Jsoup.parse(str);
    List<IHistoryDailyPicks> dailyPicksList = new ArrayList<>();
    Elements element = document.getElementsByClass("tuijian").get(0)
            .getElementsByClass("box");
    for (Element element2 : element) {
        IHistoryDailyPicks dailyPicks = new IHistoryDailyPicks();
        Element info = element2.getElementsByClass("info").get(0);
        dailyPicks.setTitle(info.getElementsByTag("a").text());// title
        String time = info.getElementsByClass("time").text().trim();
        dailyPicks.setTime(time.substring(0, time.length() - 1));// time
        dailyPicks.setDiscuss(info.getElementsByClass("pinglun").text());// Discuss
        dailyPicks.setDescribe(element2.getElementsByClass("info1").text());// Describe
        dailyPicks.setHref(AppUtils.Constants.URL_ILISHI + info.getElementsByTag("a").attr("href"));// Href
        dailyPicks.setImgHref(AppUtils.Constants.URL_ILISHI + element2.getElementsByTag("img").attr("src"));// imgHref
        dailyPicksList.add(dailyPicks);
    }
    return dailyPicksList;
}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:25,代码来源:HttpApiImpl.java

示例6: clientId

import org.jsoup.nodes.Element; //导入依赖的package包/类
public static String clientId() throws ReCaptchaException, IOException, RegexException {
    if (clientId != null && !clientId.isEmpty()) return clientId;

    Downloader dl = NewPipe.getDownloader();

    String response = dl.download("https://soundcloud.com");
    Document doc = Jsoup.parse(response);

    // TODO: Find a less heavy way to get the client_id
    // Currently we are downloading a 1MB file (!) just to get the client_id,
    // youtube-dl don't have a way too, they are just hardcoding and updating it when it becomes invalid.
    // The embed mode has a way to get it, but we still have to download a heavy file (~800KB).
    Element jsElement = doc.select("script[src^=https://a-v2.sndcdn.com/assets/app]").first();
    String js = dl.download(jsElement.attr("src"));

    return clientId = Parser.matchGroup1(",client_id:\"(.*?)\"", js);
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:18,代码来源:SoundcloudParsingHelper.java

示例7: getTeachersData

import org.jsoup.nodes.Element; //导入依赖的package包/类
public TeachersData getTeachersData() throws IOException {
    Document doc = snp.getSnPPageDocument(SCHOOL_PAGE_URL);
    Elements rows = doc.select(".mainContainer > table tbody tr");
    String description = doc.select(".mainContainer > p").first().text();

    List<Subject> subjects = new ArrayList<>();

    for (Element subject : rows) {
        subjects.add(new Subject()
                .setName(subject.select("td").get(1).text())
                .setTeachers(subject.select("td").get(2).text().split(", "))
        );
    }

    return new TeachersData()
            .setClassName(description.split(", ")[0].split(": ")[1].trim())
            .setClassTeacher(description.split("Wychowawcy:")[1].trim().split(", "))
            .setSubjects(subjects);
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:20,代码来源:TeachersInfo.java

示例8: getTopTopics

import org.jsoup.nodes.Element; //导入依赖的package包/类
private ArrayList<Topic> getTopTopics(Document doc) throws Exception{
    ArrayList<Topic> topTopics = new ArrayList<>();
    Elements elements = doc.getElementsByClass("col-12 col-sm-6 col-md-4 mb-4");
    for (Element element : elements) {
        Element idElement = element.select("a").first();
        Element imageElement = element.select("a > img").first();
        Element titleElement = element.select("a > p").get(0);
        Element descElement = element.select("a > p").get(1);

        String id = idElement.attr("href");
        id = id.substring(id.lastIndexOf("/") + 1);
        String name = titleElement.textNodes().get(0).text();
        String desc = descElement.textNodes().get(0).text();
        String image = imageElement == null ? null : imageElement.attr("src");

        Topic topic = new Topic()
                .setId(id)
                .setName(name)
                .setDesc(desc)
                .setImage(image);
        topTopics.add(topic);
    }
    return topTopics;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:25,代码来源:TopicsPresenter.java

示例9: savePandaLivesToRedis

import org.jsoup.nodes.Element; //导入依赖的package包/类
private void savePandaLivesToRedis(Document document) {
    List<Video> lives = new ArrayList<>();
    Elements elements = document.select("li.video-list-item.video-no-tag");
    for (Element element : elements) {
        Video videoDTO = new Video();
        String title = element.select("div.video-info span.video-nickname").text();
        String image = element.select("img.video-img").attr("data-original");
        image = image.replace("http:", "");
        String url = PANDA + element.attr("data-id");
        videoDTO.setTitle(title);
        videoDTO.setImage(image);
        videoDTO.setValue(url);
        lives.add(videoDTO);
        if (lives.size() > 48) {
            break;
        }
    }
    String key = redisSourceManager.VIDEO_PREFIx_HOME_LIVE_KEY + "_" + TAG;
    redisSourceManager.saveVideos(key, lives);
}
 
开发者ID:BENULL,项目名称:LushX,代码行数:21,代码来源:PandaCrawler.java

示例10: getRelatedVideos

import org.jsoup.nodes.Element; //导入依赖的package包/类
@Override
public StreamInfoItemCollector getRelatedVideos() throws IOException, ExtractionException {
    assertPageFetched();
    try {
        StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
        Element ul = doc.select("ul[id=\"watch-related\"]").first();
        if (ul != null) {
            for (Element li : ul.children()) {
                // first check if we have a playlist. If so leave them out
                if (li.select("a[class*=\"content-link\"]").first() != null) {
                    collector.commit(extractVideoPreviewInfo(li));
                }
            }
        }
        return collector;
    } catch (Exception e) {
        throw new ParsingException("Could not get related videos", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:20,代码来源:YoutubeStreamExtractor.java

示例11: removeUselessElements

import org.jsoup.nodes.Element; //导入依赖的package包/类
private static void removeUselessElements(Element element) {
    for (Element child : element.children()) {
        if (child.children().size() > 0)
            removeUselessElements(child);
        else {
            switch (child.tagName()) {
                case "br":
                case "a":
                case "p":
                case "h1":
                case "h2":
                case "h3":
                case "h4":
                case "span":
                    break;
                default:
                    Element parent = child.parent();
                    child.remove();
                    parent.insertChildren(0, child.children());
                    break;
            }
        }
    }
}
 
开发者ID:TheAndroidMaster,项目名称:Blackboard,代码行数:25,代码来源:HtmlUtils.java

示例12: getValueText

import org.jsoup.nodes.Element; //导入依赖的package包/类
private Object getValueText(Elements elements, JsoupExpression jsoupExpression) {
    if (elements == null || elements.isEmpty()) {
        return null;
    }
    Element element = elements.get(0);

    if (jsoupExpression.isTextMethod()) {
        return StringUtils.trim(element.text());
    }
    if (jsoupExpression.isValMethod()) {
        return StringUtils.trim(element.val());
    }
    if (jsoupExpression.isAttrMethod()) {
        return StringUtils.trim(element.attr(jsoupExpression.getParameter()));
    }
    if (jsoupExpression.isOuterHtmlMethod()) {
        return StringUtils.trim(element.outerHtml());
    }
    if (jsoupExpression.isOwnTextMethod()) {
        return StringUtils.trim(element.ownText());
    }
    if (jsoupExpression.isHtmlMethod()) {
        return StringUtils.trim(element.html());
    }
    return StringUtils.trim(element.text());
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:27,代码来源:JsoupParser.java

示例13: constructGameFromHtmlBlock

import org.jsoup.nodes.Element; //导入依赖的package包/类
private Game constructGameFromHtmlBlock(Element currentHtmlBlock) {
    Game gameFromHtmlBlock = DefaultFactory.Game.constructDefault();
    gameFromHtmlBlock.setScoreType(getScoreType());
    gameFromHtmlBlock.setLeagueType(this);
    Elements updatedHtmlBlocks = currentHtmlBlock.select("td");
    boolean once = true;
    int position = 0;
    for (Element currentColumnBlock : updatedHtmlBlocks) {
        if (once) {
            once = false;
            createGameInfo(Jsoup.parse(currentColumnBlock.html().replaceAll("(?i)<br[^>]*>", "br2n")).text(), gameFromHtmlBlock);

        } else {
            createBidInfo(Jsoup.parse(currentColumnBlock.html().replaceAll("(?i)<br[^>]*>", "br2n")).text(), gameFromHtmlBlock, position == 2);
        }
        position++;
    }
    gameFromHtmlBlock.setVIBid();
    gameFromHtmlBlock.createID();
    return gameFromHtmlBlock;
}
 
开发者ID:riteshakya037,项目名称:Android-Scrapper,代码行数:22,代码来源:LeagueBase.java

示例14: getStringResNameAndValueMap

import org.jsoup.nodes.Element; //导入依赖的package包/类
/**
 * 获取strings.xml 资源名-值 映射表
 *
 * @return
 */
protected Map<String, String> getStringResNameAndValueMap() {
    Map<String, String> map = new HashMap<>();

    Document document = getValuesXmlDocument();
    Elements strings  = document.getElementsByTag("string");

    for (int i = 0; i < strings.size(); i++) {
        Element element = strings.get(i);
        String  name    = element.attr("name");

        if (element.childNodeSize() > 0 && element.childNode(0) instanceof TextNode) {
            String text = ((TextNode) element.childNode(0)).text();

            map.put(name, text);
        }
    }

    return map;
}
 
开发者ID:kkmike999,项目名称:KBUnitTest,代码行数:25,代码来源:ShadowResources.java

示例15: clean

import org.jsoup.nodes.Element; //导入依赖的package包/类
protected String clean(Element element) {
    Element work = element.clone();
    String[] unwantedElements = "img,script,style,link,canvas".split(",");
    String[] unwantedAttributes = "style,class,target,id,src".split(",");
    for (String tag : unwantedElements) {
        work.getElementsByTag(tag).forEach((el) -> {
            el.remove();
        });
    }
    for (String attr : unwantedAttributes) {
        work.getElementsByAttribute(attr).forEach((el) -> {
            el.removeAttr(attr);
        });
    }
    return work.html().replaceAll("\\s{2,}", " ");
}
 
开发者ID:Idrinths-Stellaris-Mods,项目名称:Mod-Tools,代码行数:17,代码来源:RemoteModParser.java


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