本文整理匯總了Java中org.jsoup.select.Elements.attr方法的典型用法代碼示例。如果您正苦於以下問題:Java Elements.attr方法的具體用法?Java Elements.attr怎麽用?Java Elements.attr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jsoup.select.Elements
的用法示例。
在下文中一共展示了Elements.attr方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getVidStreamingVideo
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private String getVidStreamingVideo(String url) {
String videoUrl = "";
try {
Document docdata = Jsoup.connect(url).userAgent(getUserAgent())
.referrer("http://www.google.com")
.timeout(Parser.getParseTimeOut()).get();
Elements eles = docdata.select("div[class=videocontent]").select("video[id=my-video-player]").select("source");
String tempUrl = "";
if (eles != null && !eles.isEmpty()) {
for (Element ele : eles) {
tempUrl = ele.attr("abs:src");
if (!TextUtils.isEmpty(tempUrl))
videoUrl = tempUrl;
}
} else {
eles = docdata.select("div[class=videocontent]").select("iframe");
if (eles != null && !eles.isEmpty()) {
videoUrl = eles.attr("src");
return getVideoFromProvider(videoUrl);
}
}
} catch (IOException e) {
WriteLog.appendLog(Log.getStackTraceString(e));
}
return videoUrl;
}
示例2: rip
import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public void rip() throws IOException {
logger.info("Retrieving " + this.url);
Document doc = Http.url(url).get();
Elements videos = doc.select("div.player-container > a");
if (videos.size() == 0) {
throw new IOException("Could not find Embed code at " + url);
}
String vidUrl = videos.attr("href");
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
waitForThreads();
}
示例3: absPath
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private String absPath(String input, String baseUrl) {
Document doc = Jsoup.parse(input);
//doc.getAllElements();
//doc.head().prepend("<base href=" + baseUrl +"> </base>");
Elements link = doc.select("link");
link.attr("href", baseUrl + "/" + link.attr("href"));
return doc.toString();
}
示例4: setData
import org.jsoup.select.Elements; //導入方法依賴的package包/類
private void setData(List<FictionModel> list, int eq, String type) {
Elements select = document.select("div.blockcontent").eq(eq);
Elements itemElements = select.select("li");
list.add(getMoreTitle(type, select));
FictionModel fictionModel;
for (Element element : itemElements) {
fictionModel = new FictionModel();
Elements a = element.select("a");
fictionModel.title = a.text();
fictionModel.detailUrl = a.attr("abs:href");
fictionModel.type = TYPE_ITEM;
list.add(fictionModel);
}
}
示例5: extractLink
import org.jsoup.select.Elements; //導入方法依賴的package包/類
public String extractLink(Element td) {
Elements href = td.select("a");
if (!href.isEmpty()) {
//<i><a href="/wiki/1001_Spikes" title="1001 Spikes">1001 Spikes</a></i>
return href.attr("href");
}
return null;
}
示例6: episodeSelect
import org.jsoup.select.Elements; //導入方法依賴的package包/類
/**
* 웹툰별 에피소드 입력
*
* @param webCode
* - 웹툰코드
*/
public void episodeSelect(String webCode) {
try {
Document document = Jsoup.connect("http://comic.naver.com/webtoon/list.nhn?titleId=" + webCode).get();
Elements elements = document.select("ul.btn_group li").eq(1);
String[] parseTag = elements.html().split("return");
int index = parseTag[1].indexOf(")");
String functionName = parseTag[1].substring(0, index);
String firstEpisode = functionName.split(",")[1].replaceAll("'", "");
sEp.setText(firstEpisode);
elements = document.select("table.viewList > tbody > tr > td.title a").eq(0);
String href = elements.attr("href");
if ((!href.equals("")) || (href == null)) {
String real_ep = href.split("no=")[1].split("&")[0];
elements = document.select(".detail p");
dEp.setText(real_ep);
}
sEp.setEditable(true);
dEp.setEditable(true);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: scrapeHtml
import org.jsoup.select.Elements; //導入方法依賴的package包/類
public static String scrapeHtml(String webHtml) {
Document doc = Jsoup.parse(webHtml);
Elements rssTag = doc.select("link[type='application/atom+xml']");
String rssHref = rssTag.attr("href");
return rssHref;
}
示例8: getAlbumTitle
import org.jsoup.select.Elements; //導入方法依賴的package包/類
public String getAlbumTitle(URL url) throws MalformedURLException {
String gid = getGID(url);
if (this.albumType == ALBUM_TYPE.ALBUM) {
try {
// Attempt to use album title as GID
if (albumDoc == null) {
albumDoc = Http.url(url).get();
}
Elements elems = null;
/*
// TODO: Add config option for including username in album title.
// It's possible a lot of users would not be interested in that info.
String user = null;
elems = albumDoc.select(".post-account");
if (elems.size() > 0) {
Element postAccount = elems.get(0);
if (postAccount != null) {
user = postAccount.text();
}
}
*/
String title = null;
final String defaultTitle1 = "Imgur: The most awesome images on the Internet";
final String defaultTitle2 = "Imgur: The magic of the Internet";
logger.info("Trying to get album title");
elems = albumDoc.select("meta[property=og:title]");
if (elems != null) {
title = elems.attr("content");
logger.debug("Title is " + title);
}
// This is here encase the album is unnamed, to prevent
// Imgur: The most awesome images on the Internet from being added onto the album name
if (title.contains(defaultTitle1) || title.contains(defaultTitle2)) {
logger.debug("Album is untitled or imgur is returning the default title");
// We set the title to "" here because if it's found in the next few attempts it will be changed
// but if it's nto found there will be no reason to set it later
title = "";
logger.debug("Trying to use title tag to get title");
elems = albumDoc.select("title");
if (elems != null) {
if (elems.text().contains(defaultTitle1) || elems.text().contains(defaultTitle2)) {
logger.debug("Was unable to get album title or album was untitled");
}
else {
title = elems.text();
}
}
}
String albumTitle = "imgur_";
/*
// TODO: Add config option (see above)
if (user != null) {
albumTitle += "user_" + user;
}
*/
albumTitle += gid;
if (title != null) {
albumTitle += "_" + title;
}
return albumTitle;
} catch (IOException e) {
// Fall back to default album naming convention
}
}
return getHost() + "_" + gid;
}
示例9: run
import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public void run() {
Document doc;
try {
doc = get(mUrl);
} catch (IOException e) {
e.printStackTrace();
failedOnUI(e.getMessage());
return;
}
Elements topicDetailElements = doc.select("div.topic-detail");
if (topicDetailElements.isEmpty()) {
failedOnUI("找不到主題詳情");
return;
}
Elements elements = topicDetailElements.select("div.ui-header");
if (elements.isEmpty()) {
failedOnUI("找不到主題元信息");
return;
}
TopicDetail topicDetail = new TopicDetail();
Topic topic = GetTopicListTask.createTopicFromElement(elements.first());
topicDetail.setTopic(topic);
// 解析收藏
Elements favouriteElement = doc.select(".J_topicFavorite");
if(favouriteElement!=null){
String hrefUrl = favouriteElement.attr("href");
String dataType = favouriteElement.attr("data-type");
String text = favouriteElement.text();
Favorite favorite = new Favorite();
favorite.setUrl(hrefUrl);
favorite.setDataType(dataType);
favorite.setText(text);
topicDetail.setFavorite(favorite);
}
elements = topicDetailElements.select("div.ui-content");
if (elements.isEmpty()) {
failedOnUI("找不到主題內容");
return;
}
topicDetail.setContent(elements.first().outerHtml());
Elements commentsElements = doc.select("div.topic-reply");
Map<Integer, Comment> comments = GetCommentsTask.getCommentsFromElements(commentsElements);
topicDetail.setComments(comments);
successOnUI(topicDetail);
}
示例10: getEpisodeVideo
import org.jsoup.select.Elements; //導入方法依賴的package包/類
@Override
public String getEpisodeVideo(String url) {
String videoUrl = "";
try {
Document docdata = load(url, true);
Elements videoEle = docdata.select("div[class=play-video]").select("iframe");
if (videoEle != null && !videoEle.isEmpty()) {
String tempUrl = videoEle.attr("abs:src");
videoUrl = getVideoFromProvider(tempUrl);
if (!TextUtils.isEmpty(videoUrl))
return videoUrl;
}
Elements downloadEle = docdata.select("div[class=anime_video_body]")
.select("div[class=download-anime]").select("a");
if (downloadEle != null && !downloadEle.isEmpty()) {
String downloadLink = downloadEle.get(0).attr("href");
if (!TextUtils.isEmpty(downloadLink)) {
videoUrl = getInternalVideoUrlAniUploader(downloadLink);
if (!TextUtils.isEmpty(videoUrl)) {
return videoUrl;
}
}
} else {
Elements eles = docdata.select("div[id=video_container_div]").select("script");
if (eles != null && !eles.isEmpty()) {
Element playerScript = eles.last();
if (playerScript != null) {
String scriptText[] = playerScript.html().split("\n");
if (scriptText != null && scriptText.length > 0) {
for (int i = 0; i < scriptText.length; i++) {
if (scriptText[i].contains("file:")) {
videoUrl = scriptText[i].trim().replace("file: '", "").replace("',", "");
break;
}
}
}
}
//videoUrl = eles.select("video").select("source").attr("abs:src");
} else {
eles = docdata.select("iframe[class=mirrorVid]");
if (eles != null && !eles.isEmpty()) {
videoUrl = eles.attr("src");
if (!TextUtils.isEmpty(videoUrl))
videoUrl = getVideoFromProvider(videoUrl);
}
}
}
} catch (IOException e) {
WriteLog.appendLog(Log.getStackTraceString(e));
}
return videoUrl;
}
示例11: parseTutorias
import org.jsoup.select.Elements; //導入方法依賴的package包/類
public List<TutoriaData> parseTutorias(boolean isNew, String text, SubjectData subject) {
List<TutoriaData> tutorias = new ArrayList<>();
try {
JSONObject jdata = new JSONObject(text);
if (jdata.has("aaData")) {
JSONArray jarray = jdata.getJSONArray("aaData");
for (int i = 0; i < jarray.length(); i++) {
TutoriaData tutoria = new TutoriaData();
JSONArray jtutoria = jarray.getJSONArray(i);
String name;
String state;
String html;
String id;
if (isNew) {
name = jtutoria.getString(0);
state = "";
html = jtutoria.getString(3);
id = jtutoria.getString(4);
} else {
name = jtutoria.getString(0);
state = jtutoria.getString(3);
if (state.contains("pendiente")) {
state = context.getString(R.string.tutoria_without_answer);
}
html = jtutoria.getString(4);
id = jtutoria.getString(5);
}
Document doc = Jsoup.parse(html);
Elements elements = doc.select("img");
String user = elements.attr("title");
String src = elements.attr("src");
String sname = AppManager.after(subject.getName(), parseYear() + " ");
sname = AppManager.before(sname, "(" + subject.getId());
tutoria.setSubject(subject.getId());
tutoria.setSubjectName(sname);
tutoria.setTitle(name);
tutoria.setId(id);
tutoria.setLastModify(state);
tutoria.setTeacherName(user);
tutoria.setTeacherPicture(src);
tutorias.add(tutoria);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return tutorias;
}