本文整理汇总了Java中org.jsoup.nodes.Document.getElementById方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getElementById方法的具体用法?Java Document.getElementById怎么用?Java Document.getElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Document
的用法示例。
在下文中一共展示了Document.getElementById方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseDateStatesMap
import org.jsoup.nodes.Document; //导入方法依赖的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;
}
示例2: Main
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
public static void Main(String[] args) throws IOException {
Calendar cal = Calendar.getInstance();
// cal.add(Calendar.DAY_OF_MONTH, -1);
// String timeStamp = new SimpleDateFormat("yyyyMMdd").format(cal)+"0";
String timeStamp = "201706120";
String url = "https://www.basketball-reference.com/boxscores/" + timeStamp + "GSW.html";
Document doc = Jsoup.connect(url).get();
Element line_score = doc.getElementById("div_line_score");
String away_team_name = line_score.getElementsByTag("tr").get(1).getElementsByTag("td").get(1).text();
String home_team_name = line_score.getElementsByTag("tr").get(2).getElementsByTag("td").get(1).text();
Element all_four_factors = doc.getElementById("all_four_factors");
Element box_away_basic = doc.getElementById("all_box_cle_basic");
Element box_away_advanced = doc.getElementById("all_box_cle_advanced");
Element box_home_basic = doc.getElementById("all_box_gsw_basic");
Element box_home_advanced = doc.getElementById("all_box_gsw_advanced");
System.out.println(away_team_name + home_team_name);
}
示例3: getDownloadPageURL
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
/**
*
* @return
*/
private String getDownloadPageURL() {
try {
Document document = Jsoup.connect(this.jdkURL).get();
// Parsing div element having id 'Wrapper_FixedWidth_Centercontent'
Element element = document.getElementById("Wrapper_FixedWidth_Centercontent");
// Parsing div elements having class attribute of 'orcl6w3'
// Getting first element from elements
element = element.select("div[class$=orcl6w3]").get(0);
// Parsing all tables from the element where desired link isplaced
// Getting first element from parsed tables
element = element.getElementsByTag("table").get(0);
// Parsing all links from the following table
// First element is the desired link
element = element.getElementsByTag("a").get(0);
// Parsing the href content from the link [a] tag
this.downloadURL = this.oracleURL + element.attr("href");
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
return this.downloadURL;
}
示例4: parseCaptchaId
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
@Override
public Optional<String> parseCaptchaId(HttpResponse httpResponse) {
try {
InputStream content = httpResponse.getEntity().getContent();
Document document = jsoupDocumentFactory.create(content);
Element captchaImg = document.getElementById("MainContent_ctrlCaptcha2");
String url = captchaImg.attr("src").replace("\r\n", "");
URIBuilder uriBuilder = new URIBuilder(url);
return uriBuilder.getQueryParams().stream()
.filter(nameValuePair -> nameValuePair.getName().equals("id"))
.map(NameValuePair::getValue)
.findAny();
} catch (IOException | URISyntaxException ex) {
return Optional.empty();
}
}
示例5: findOrders
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
private ArrayList<ApsvOrder> findOrders(String html) {
//logger.info("Html: {}", html);
ArrayList<ApsvOrder> orders = new ArrayList<>();
Document doc = Jsoup.parse(html);
Element ordersForm = doc.getElementById("J-submit-form");
if (ordersForm == null) {
logger.error("Cannot find order list form, maybe cookie expires");
// 标记task status为异常
// TODO 弹窗提醒cookie异常
RunTasksModel.getInstance().MarkTaskException(task.id);
return orders;
}
Elements tableBody = doc.select("#tradeRecordsIndex>tbody");
Elements orderRows = tableBody.select("tr");
orderRows.forEach(row -> {
Elements timeNodes = row.select("td.time p");
String[] orderNoData = row.select("td.tradeNo p").text().split("\\|");
ApsvOrder order = new ApsvOrder(){
{
taskId = task.id;
time = timeNodes.get(0).text() + " " + timeNodes.get(timeNodes.size() - 1).text();
description = row.select(".memo-info").text();
memo = row.select("td.memo p").text();
tradeNo = orderNoData.length > 1 ? orderNoData[1].split(":")[1] : orderNoData[0].split(":")[1];
username = Unicode.unicodeToString(row.select("td.other p").text());
amount = Float.parseFloat(row.select("td.amount span").text().replaceAll("\\s+", ""));
status = row.select("td.status p").text();
}
};
order.sig = Order.Sign(order, task.pushSecret);
orders.add(order);
});
return orders;
}
示例6: team_name_isValid
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
@Test
public void team_name_isValid() throws Exception {
String url = "https://www.basketball-reference.com/boxscores/201706120GSW.html";
Document doc = Jsoup.connect(url).get();
Element line_score = doc.getElementById("div_line_score");
String away_team_name = line_score.getElementsByTag("tr").get(1).getElementsByTag("td").get(1).text();
assertEquals(away_team_name, "CLE");
}
示例7: parse
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
private HanZiDM parse(Document doc) throws Exception {
Element contentEL = doc.getElementById("tagContent0");
String wubi=this.gatherWuBi(contentEL);
wubi=checkNotNone("无法找到五笔节点内容", wubi);
String bihua=this.gatherBiHua(contentEL);
bihua=checkNotNone("无法找到笔画节点内容", bihua);
List<DuYinDM> duYins=this.gatherDuyins(contentEL);
HanZiDM dm=new HanZiDM();
dm.setWubi(wubi);
dm.setBihua(bihua.length());
dm.setDuyins(duYins);
return dm;
}
示例8: syncStockInfos
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
@PostMapping("/lottery-details/sync")
@ResponseStatus(HttpStatus.OK)
public void syncStockInfos() throws IOException {
int yearStart = ConfigConstant.START_LOTTERY_YEAR;
LotteryDetail lotteryDetail = lotteryDetailRepository.findTopByOrderByLotteryYearDescLotteryPeriodDesc();
if (lotteryDetail != null) {
yearStart = lotteryDetail.getLotteryYear();
}
int yearEnd = DateUtils.getYear(new Date());
while (yearStart <= yearEnd) {
String url = ConfigConstant.LOTTERY_URL + yearStart + ".html";
logger.debug("采集六合彩url:{}", url);
Document doc = Jsoup.connect(url).get();
Element element = doc.getElementById("main");
Element tbody = element.getElementsByTag("tbody").get(0);
Elements trElements = tbody.select(".infolist");
for (Element trElement : trElements) {
Elements tdElements = trElement.select("td");
Date date = DateUtils.parseDate(tdElements.get(0).text());
int lotteryYear = DateUtils.getYear(date);
String lotteryPeriodStr = tdElements.get(1).text();
int index = lotteryPeriodStr.indexOf("期");
int lotteryPeriod = ObjectUtils.convertToInteger(lotteryPeriodStr.substring(0, index));
String lotteryNumberStr = tdElements.get(2).text();
String[] lotteryNumbers = lotteryNumberStr.split(" ");
String lotteryCodeStr = tdElements.get(3).text();
int lotteryCode = ObjectUtils.convertToInteger(lotteryCodeStr.split(" ")[0]);
logger.debug("采集六合彩:lotteryYear:{}lotteryPeriodStr:{},lotteryCode:{}", lotteryYear, lotteryPeriod, lotteryCode);
saveLotteryDetail(lotteryYear, lotteryPeriod, lotteryCode, lotteryNumbers);
}
yearStart++;
}
}
示例9: syncStockInfos
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
@PostMapping("/stock-infos/sync")
@ResponseStatus(HttpStatus.OK)
public void syncStockInfos() throws IOException {
Document doc = Jsoup.connect(ConfigConstant.STOCK_INFO_URL).get();
Element element = doc.getElementById("quotesearch");
Elements ulElements = element.select("ul");
for (Element ulElement : ulElements) {
Elements liElements = ulElement.select("li");
for (Element liElement : liElements) {
Elements children = liElement.children();
if (!children.isEmpty()) {
String stockInfo = children.get(0).text();
if (ObjectUtils.isNotEmpty(stockInfo)) {
stockInfo = stockInfo.substring(0, stockInfo.length() - 1);
String[] stockInfos = stockInfo.split("\\(");
String stockName = stockInfos[0];
String stockCode = stockInfos[1];
if (stockCode.startsWith(ConfigConstant.SH_STOCK_PRE)) {
saveStockInfo(stockCode, stockName, ConfigConstant.STOCK_TYPE_SH);
} else if (stockCode.startsWith(ConfigConstant.SZ_STOCK_PRE)) {
saveStockInfo(stockCode, stockName, ConfigConstant.STOCK_TYPE_SZ);
} else if (stockCode.startsWith(ConfigConstant.CY_STOCK_PRE)) {
saveStockInfo(stockCode, stockName, ConfigConstant.STOCK_TYPE_SZ);
}
}
}
}
}
}
示例10: QuakeInfo
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
public QuakeInfo(final Document doc) {
this.url = "https://typhoon.yahoo.co.jp"+Optional.ofNullable(doc.getElementById("history")).map(history -> history.getElementsByTag("tr").get(1).getElementsByTag("td").first().getElementsByTag("a").first().attr("href")).orElse("");
this.imageUrl = Optional.ofNullable(doc.getElementById("yjw_keihou").getElementsByTag("img").first()).map(image -> StringUtils.substringBefore(image.attr("src"), "?"));
final Element info = doc.getElementById("eqinfdtl");
final Map<String, String> data = info.getElementsByTag("table").get(0).getElementsByTag("tr").stream()
.map(tr -> tr.getElementsByTag("td")).collect(Collectors.toMap(td -> td.get(0).text(), td -> td.get(1).text()));
try {
this.announceTime = FORMAT.parse(data.get("情報発表時刻"));
final String quakeTime = data.get("発生時刻");
this.quakeTime = FORMAT.parse(StringUtils.substring(quakeTime, 0, quakeTime.length()-2));
this.epicenter = data.get("震源地");
this.lat = data.get("緯度");
this.lon = data.get("経度");
this.depth = data.get("深さ");
this.magnitude = NumberUtils.toFloat(data.get("マグニチュード"), -1f);
this.info = data.get("情報");
} catch (final ParseException e) {
throw new RuntimeException("Parse Error", e);
}
final Element yjw = info.getElementsByTag("table").get(1);
if (yjw.childNodeSize()<=1)
this.maxIntensity = Optional.empty();
else
this.maxIntensity = SeismicIntensity.get(yjw.getElementsByTag("td").first().getElementsByTag("td").first().text());
final Map<String, PrefectureDetail> details = new HashMap<>();
yjw.getElementsByTag("tr").stream().filter(tr -> tr.attr("valign").equals("middle")).forEach(tr -> {
final Optional<SeismicIntensity> intensity = SeismicIntensity.get(tr.getElementsByTag("td").first().getElementsByTag("td").first().text());
tr.getElementsByTag("table").first().getElementsByTag("tr").stream().map(line -> line.getElementsByTag("td")).collect(Collectors.toMap(td -> td.get(0).text(), td -> td.get(1).text())).entrySet().forEach(entry -> {
final String prefecture = entry.getKey();
final PrefectureDetail detail = details.computeIfAbsent(prefecture, key -> new PrefectureDetail(prefecture));
intensity.ifPresent(line -> Stream.of(StringUtils.split(entry.getValue(), " ")).forEach(str -> detail.addCity(line, str)));
});
});
this.details = new ArrayList<>(details.values());
Collections.sort(this.details, Comparator.reverseOrder());
}
示例11: parse
import org.jsoup.nodes.Document; //导入方法依赖的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;
}
示例12: onResponse
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
@Override
public void onResponse(String response) {
// Hide icon
findViewById(R.id.noNetwork).setVisibility(View.INVISIBLE);
Document doc = Jsoup.parse(response);
// If article was loaded from an external App, no image was passed from MainActivity,
// so it must be fetched in the Collapsing Toolbar
if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
Elements image = doc.select("meta[property=og:image]");
if (atLeastOneChild(image)) {
Picasso.with(ArticleActivity.this)
.load(image.first().attr("content"))
.into((ImageView) findViewById(R.id.imageArticle));
}
}
// Article is from a hosted blog
List<Model> items;
Element content = doc.getElementById("content");
if (content != null) {
items = extractBlogArticle(content);
setTagInHeader(R.string.blog_article, R.color.accent_complementary, Color.WHITE);
} else {
Elements category = doc.select("div.tt_rubrique_ombrelle");
if (atLeastOneChild(category)) {
Log.d(TAG, "Cat: " + category.text());
setTitle(category.text());
}
Elements articles = doc.getElementsByTag("article");
Element largeFormat = doc.getElementById("hors_format");
if (largeFormat != null) {
items = new ArrayList<>();
setTagInHeader(R.string.large_article, R.color.primary_dark, Color.WHITE);
} else if (articles.isEmpty()) {
// Video
items = extractVideo(doc);
setTagInHeader(R.string.video_article, R.color.accent_complementary, Color.WHITE);
} else {
// Standard article
items = extractStandardArticle(articles);
// Full article is restricted to paid members
if (doc.getElementById("teaser_article") != null) {
if (menu != null) {
MenuItem menuItem = menu.findItem(R.id.action_share);
if (menuItem != null) {
menuItem.setIcon(getResources().getDrawable(R.drawable.ic_share_black));
}
} else {
Log.e(TAG, "menu should not be null at this point!");
}
CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setContentScrimResource(R.color.accent);
setTagInHeader(R.string.paid_article, R.color.accent, Color.BLACK);
if (getSupportActionBar() != null) {
final Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_black_24dp);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
}
}
// After parsing the article, start a new request for comments
Element react = doc.getElementById("liste_reactions");
if (react != null) {
Elements dataAjURI = react.select("[^data-aj-uri]");
if (atLeastOneChild(dataAjURI)) {
String commentPreviewURI = Constants.BASE_URL2 + dataAjURI.first().attr("data-aj-uri");
REQUEST_QUEUE.add(new StringRequest(Request.Method.GET, commentPreviewURI, commentsReceived, errorResponse));
}
}
}
}
articleAdapter.insertItems(items);
findViewById(R.id.articleLoader).setVisibility(View.GONE);
}
示例13: fill
import org.jsoup.nodes.Document; //导入方法依赖的package包/类
protected void fill(Modification mod, EntityManager manager) {
try {
Document doc = getDocument();
if (null != doc.getElementById("highlightContent")) {
mod.setDescription(clean(doc.getElementById("highlightContent")));
System.out.println("Added description for remote id " + id);
}
if (null != doc.getElementsByClass("workshopItemTitle").first()) {
mod.setName(doc.getElementsByClass("workshopItemTitle").first().text());
System.out.println("Added title for remote id " + id);
}
if (null != doc.getElementById("RequiredItems")) {
Pattern reg = Pattern.compile("https?://(www\\.)?steamcommunity\\.com/workshop/filedetails/\\?id=([0-9]+).*");
for (Element link : doc.getElementById("RequiredItems").getElementsByTag("a")) {
if (link.hasAttr("href")) {
int lId = match(reg.matcher(link.attr("href")));
if (lId > 0) {
todo.add(new RemoteModParser(lId));
mod.getOverwrite().add(getOrCreateModForId(lId, manager));
}
}
}
System.out.println("Added required items for remote id " + id);
}
} catch (IOException ex) {
System.out.println(ex.getLocalizedMessage());
}
}