本文整理匯總了Java中org.jsoup.select.Elements.first方法的典型用法代碼示例。如果您正苦於以下問題:Java Elements.first方法的具體用法?Java Elements.first怎麽用?Java Elements.first使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jsoup.select.Elements
的用法示例。
在下文中一共展示了Elements.first方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchImage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private void fetchImage() {
try {
Document doc = Http.url(url)
.retries(3)
.get();
// Find image
Elements images = doc.select("a > img");
if (images.size() == 0) {
logger.warn("Image not found at " + this.url);
return;
}
Element image = images.first();
String imgsrc = image.attr("src");
imgsrc = "http://" + this.url.getHost() + "/" + imgsrc;
// Provide prefix and let the AbstractRipper "guess" the filename
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(imgsrc), prefix);
} catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url, e);
}
}
示例2: fetchImage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private void fetchImage() {
try {
Document doc = Http.url(url).get();
// Find image
Elements images = doc.select(".image-container img");
if (images.size() == 0) {
logger.warn("Image not found at " + this.url);
return;
}
Element image = images.first();
String imgsrc = image.attr("src");
logger.info("Found URL " + imgsrc);
// Provide prefix and let the AbstractRipper "guess" the filename
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(imgsrc), prefix);
} catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url, e);
}
}
示例3: getNextPage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public Document getNextPage(Document page) throws IOException {
if (isThisATest()) {
return null;
}
Elements nextButtons = page.select("link[rel=\"next\"]");
if (nextButtons.size() == 0) {
if (page.select("link[rel=\"prev\"]").size() == 0) {
throw new IOException("No next page found");
} else {
throw new IOException("Hit end of pages");
}
}
Element a = nextButtons.first();
String nextPage = a.attr("href");
if (nextPage.startsWith("/")) {
nextPage = "http://" + this.url.getHost() + nextPage;
}
if (!sleep(PAGE_SLEEP_TIME)) {
throw new IOException("Interrupted while waiting to load next page: " + nextPage);
}
logger.info("Found next page: " + nextPage);
return Http.url(nextPage)
.cookies(cookies)
.get();
}
示例4: fetchImage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private void fetchImage() {
try {
Document doc = Http.url(this.url)
.referrer(this.url)
.get();
// Find image
Elements images = doc.select("#photoImageSection img");
Element image = images.first();
String imgsrc = image.attr("src");
logger.info("Found URL " + imgsrc + " via " + images.get(0));
// Provide prefix and let the AbstractRipper "guess" the filename
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
URL imgurl = new URL(url, imgsrc);
addURLToDownload(imgurl, prefix);
} catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url, e);
}
}
示例5: getSelectorByName
import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
* 對與頁麵 的 一些動態通過js填充內容的select 的內容進行 提取,並封裝成Doc 元素
* @param html
* @return
*/
public static Element getSelectorByName(String html,String selectName){
if(html==null) return null;
Document doc = Jsoup.parse(html);
Elements selectors =null;
//先去頁麵拿 ,如果拿不到,或者拿到的是空的 列表,則在js拿
selectors=doc.select("select[name="+selectName+"]");
if(selectors!=null&&selectors.select("option").size()>0&&selectors.text()!=null&&!selectors.text().trim().equals("")){
return selectors.first();
}
//首先去js裏麵拿,拿不到再去頁麵拿
selectors=doc.select("script");
if(selectors!=null&&selectors.size()>0){
String seletorHtml=selectors.html().replaceAll("[\\s\\S]*(<select[\\w\\W]*>[\\w\\W]+</select>)", "$1");
Document docTemp = Jsoup.parse("<html>"+seletorHtml+"</html>");
return docTemp.select("select[name="+selectName+"]").first();
}
return null;
}
示例6: downLoadPict
import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
* 下載圖片到臨時路徑
*/
public void downLoadPict(String songId) {
String downUrl = "http://music.163.com/song/29802464";
if (songId != null) {
downUrl = songId;
}
int i = 0;
Elements select = null;
try {
select = Jsoup.connect(downUrl)
.header("Referer", "http://music.163.com/")
.header("Host", "music.163.com").get().select("img[src]");
Element first = select.first();
String attr = first.attr("abs:src");
i = HttpClientUtil.doDownload(attr, FILE_PATH);
LOGGER.info("圖片下載成功" + i);
} catch (IOException e) {
LOGGER.error("圖片下載失敗", e);
}
}
示例7: fetchImage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private void fetchImage() {
try {
Document doc = getPageWithRetries(this.url);
// Find image
Elements images = doc.select(".sni > a > img");
if (images.size() == 0) {
// Attempt to find image elsewise (Issue #41)
images = doc.select("img#img");
if (images.size() == 0) {
logger.warn("Image not found at " + this.url);
return;
}
}
Element image = images.first();
String imgsrc = image.attr("src");
logger.info("Found URL " + imgsrc + " via " + images.get(0));
Pattern p = Pattern.compile("^http://.*/ehg/image.php.*&n=([^&]+).*$");
Matcher m = p.matcher(imgsrc);
if (m.matches()) {
// Manually discover filename from URL
String savePath = this.workingDir + File.separator;
if (Utils.getConfigBoolean("download.save_order", true)) {
savePath += String.format("%03d_", index);
}
savePath += m.group(1);
addURLToDownload(new URL(imgsrc), new File(savePath));
}
else {
// Provide prefix and let the AbstractRipper "guess" the filename
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(imgsrc), prefix);
}
} catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url, e);
}
}
示例8: getNextPage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public Document getNextPage(Document doc) throws IOException {
if (doc.select("li.next.hidden").size() != 0) {
// Last page
throw new IOException("No more pages");
}
Elements els = doc.select("li.next > a");
Element first = els.first();
String nextURL = first.attr("href");
nextURL = "http://www.hentai-foundry.com" + nextURL;
return Http.url(nextURL)
.referrer(url)
.cookies(cookies)
.get();
}
示例9: element
import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
* Extract first element according to a query
*/
private static Element element(Element container, String query) {
Elements select = container.select(query);
if (select.size() == 0) {
throw new ElementNotFoundException(query);
}
return select.first();
}
示例10: getCategoryList
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private static List<FlowerCategory> getCategoryList() {
List<FlowerCategory> categories = new ArrayList<FlowerCategory>();
try {
Document doc = Jsoup.connect("http://www.aihuhua.com/baike/").get();
Elements catelist = doc.getElementsByClass("catelist");
Element cates = catelist.first();
List<Node> childNodes = cates.childNodes();
for (int i = 0; i < childNodes.size(); i++) {
Node node = childNodes.get(i);
List<Node> childs = node.childNodes();
if (childs != null && childs.size() > 0) {
FlowerCategory category = new FlowerCategory();
for (int j = 0; j < childs.size(); j++) {
Node child = childs.get(j);
if ("a".equals(child.nodeName())) {
category.setUrl(child.attr("href"));
category.setImgPath(child.childNode(1).attr("src"));
} else if ("h2".equals(child.nodeName())) {
category.setName(child.attr("title"));
}
}
categories.add(category);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return categories;
}
示例11: run
import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public void run() {
try {
if (!TextUtils.isEmpty(AuthInfoManager.getInstance().getUsername()) &&
!TextUtils.isEmpty(AuthInfoManager.getInstance().getAvatar())) {
successOnUI("succeed");
return;
}
Document doc = get(ConstantUtil.BASE_URL);
Elements elements = doc.select("div.usercard");
if (!elements.isEmpty()) {
Element usercardElement = elements.first();
AuthInfoManager.getInstance().setUsername(usercardElement.select("div.username").first().text());
AuthInfoManager.getInstance().setAvatar(usercardElement.select("img.avatar").first().attr("src"));
successOnUI("succeed");
return;
}
} catch (IOException e) {
e.printStackTrace();
}
AuthInfoManager.getInstance().setUsername(null);
AuthInfoManager.getInstance().setAvatar(null);
failedOnUI("auth failed");
}
示例12: extractStandardArticle
import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
* Extract and parse a standard article. A standard article is published on the main page and by definition,
* is not: from a hosted blog, nor a video, nor a special multimedia content. It has some standardized fields like
* one (or multiple) author(s), a date, a description, an headline, a description and a list of paragraphs.
* Each paragraph is a block of text (comments included) or an image or an embedded tweet.
*
* @param articles article to analyze
* @return a list of formatted content that can be nicely displayed in the recycler view.
*/
@NonNull
private List<Model> extractStandardArticle(@NonNull Elements articles) {
TextView headLine = new TextView(this);
TextView authors = new TextView(this);
TextView dates = new TextView(this);
TextView description = new TextView(this);
int defaultText = ThemeUtils.getStyleableColor(this, R.styleable.CustomTheme_defaultText);
int authorDateText = ThemeUtils.getStyleableColor(this, R.styleable.CustomTheme_authorDateText);
headLine.setTextColor(defaultText);
description.setTextColor(defaultText);
authors.setTextColor(authorDateText);
dates.setTextColor(authorDateText);
headLine.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_headline));
authors.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_authors));
dates.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_authors));
description.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_description));
Element article = articles.first();
headLine.setText(extractAttr(article, ATTR_HEADLINE));
authors.setText(extractAttr(article, ATTR_AUTHOR));
dates.setText(extractDates(article));
shareText = extractAttr(article, ATTR_DESCRIPTION);
description.setText(shareText);
List<Model> views = new ArrayList<>();
views.add(new Model(headLine));
views.add(new Model(authors));
views.add(new Model(dates));
views.add(new Model(description));
views.addAll(extractParagraphs(article));
return views;
}
示例13: fetchImage
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private void fetchImage() {
try {
//Document doc = getPageWithRetries(this.url);
Document doc = Http.url(this.url).get();
// Find image
Elements images = doc.select("#image-container > a > img");
if (images.size() == 0) {
// Attempt to find image elsewise (Issue #41)
images = doc.select("img#img");
if (images.size() == 0) {
logger.warn("Image not found at " + this.url);
return;
}
}
Element image = images.first();
String imgsrc = image.attr("src");
logger.info("Found URL " + imgsrc + " via " + images.get(0));
Pattern p = Pattern.compile("^https?://i.nhentai.net/galleries/\\d+/(.+)$");
Matcher m = p.matcher(imgsrc);
if (m.matches()) {
// Manually discover filename from URL
String savePath = this.workingDir + File.separator;
if (Utils.getConfigBoolean("download.save_order", true)) {
savePath += String.format("%03d_", index);
}
savePath += m.group(1);
addURLToDownload(new URL(imgsrc), new File(savePath));
} else {
// Provide prefix and let the AbstractRipper "guess" the filename
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(imgsrc), prefix);
}
} catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url, e);
}
}
示例14: doAnalysis
import org.jsoup.select.Elements; //導入方法依賴的package包/類
public PublicCourseOption doAnalysis(String html){
if (html == null)
return null;
PublicCourseOption option = new PublicCourseOption();
Document doc = null;
doc = Jsoup.parse(html);
Elements elements = doc.select("#dataListDiv");
Element dataListDiv = elements.first();
if(dataListDiv==null) {
System.out.println(cNo);
return null;
}
/*
* 去掉 上課班級的那一列
*/
//
// 去掉title
Elements titleNodes = dataListDiv.select(".T");
if (titleNodes.size() == 0) {
return null;
}
for (int i = 0; i < titleNodes.size(); i = i + 2) {
titleNodes.get(i).childNode(3).remove();
}
// 去掉class =B 的 第四個節點
Elements classBNodes = dataListDiv.select(".B");
Elements classHNodes = dataListDiv.select(".H");
for (Element classBNode : classBNodes) {
classBNode.childNode(3).remove();
}
for (Element classHNode : classHNodes) {
classHNode.childNode(2).remove();
}
// System.out.println(dataListDiv);
option.setcNo(getcNo());
option.setCampus(getCampusArea());
option.setTermNo(getTermNo());
String optionHtml = dataListDiv.toString().replaceAll(
"<=\\\"\\\" d=\\\"\\\"", "").replaceAll("disabled", " ");
option.setOptionHtml(optionHtml);
return option;
}
示例15: extractVideo
import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
* This method is not functionnal at this moment.
*
* @param doc the document to analyze
* @return a list of formatted content that can be nicely displayed in the recycler view.
*/
@NonNull
private List<Model> extractVideo(@NonNull Document doc) {
Elements elements = doc.select("section.video");
if (elements.isEmpty()) {
return new ArrayList<>();
}
TextView headLine = new TextView(this);
TextView authors = new TextView(this);
TextView dates = new TextView(this);
TextView content = new TextView(this);
int defaultText = ThemeUtils.getStyleableColor(this, R.styleable.CustomTheme_defaultText);
int authorDateText = ThemeUtils.getStyleableColor(this, R.styleable.CustomTheme_authorDateText);
headLine.setTextColor(defaultText);
content.setTextColor(defaultText);
authors.setTextColor(authorDateText);
dates.setTextColor(authorDateText);
headLine.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_headline));
authors.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_authors));
dates.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_authors));
content.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.article_body));
Element video = elements.first();
headLine.setText(extractAttr(video, ATTR_HEADLINE));
authors.setText(extractAttr(video, ATTR_AUTHOR));
dates.setText(extractDates(video));
Elements els = video.select("div.grid_12.alpha");
if (atLeastOneChild(els)) {
for (Element e : els) {
Log.d(TAG, e.html());
}
els.select("h2").remove();
els.select("span.txt_gris_soutenu").remove();
els.select("#recos_videos_outbrain").remove();
fromHtml(content, els.html());
}
List<Model> views = new ArrayList<>();
views.add(new Model(headLine));
views.add(new Model(authors));
views.add(new Model(dates));
views.add(new Model(content));
return views;
}