本文整理匯總了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;
}
}
}
}
示例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;
}
示例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());
}
}
}
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
}
}
}
示例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());
}
示例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;
}
示例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;
}
示例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,}", " ");
}