本文整理汇总了Java中org.jsoup.nodes.Element.attr方法的典型用法代码示例。如果您正苦于以下问题:Java Element.attr方法的具体用法?Java Element.attr怎么用?Java Element.attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.attr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getURLsFromPage
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> URLs = new ArrayList<>();
//Pictures
Elements imgs = doc.select("div.img > img.img-front");
for (Element img : imgs) {
String imageURL = img.attr("src");
imageURL = "https:" + imageURL;
URLs.add(imageURL);
}
//Videos
Elements vids = doc.select("div.video > video > source");
for (Element vid : vids) {
String videoURL = vid.attr("src");
URLs.add("https:" + videoURL);
}
return URLs;
}
示例2: getAlbumTitle
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public String getAlbumTitle(URL url) throws MalformedURLException {
if (!is_profile(url)) {
try {
// Attempt to use album title as GID
Element titleElement = getFirstPage().select("meta[property=og:title]").first();
String title = titleElement.attr("content");
title = title.substring(title.lastIndexOf('/') + 1);
return getHost() + "_" + getGID(url) + "_" + title.trim();
} catch (IOException e) {
// Fall back to default album naming convention
logger.info("Unable to find title at " + url);
}
return super.getAlbumTitle(url);
}
return url.toExternalForm().split("/u/")[1];
}
示例3: 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;
}
示例4: getSnpPageUrl
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public String getSnpPageUrl() throws IOException, NotLoggedInErrorException {
if (null != getId()) {
return getBaseUrl();
}
// get url to uonetplus-opiekun.vulcan.net.pl
Document startPage = getPageByUrl(getStartPageUrl());
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
if (null == studentTileLink) {
throw new NotLoggedInErrorException();
}
String snpPageUrl = studentTileLink.attr("href");
this.id = getExtractedIdFromUrl(snpPageUrl);
return snpPageUrl;
}
示例5: initAdd
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
* 获取最新入库小说
*/
private void initAdd(List<FictionModel> list) {
FictionModel pushTitle = new FictionModel();
pushTitle.title = TYPE_TITLE_ADD;
pushTitle.type = TYPE_TITLE;
list.add(pushTitle);
FictionModel kswListModel;
Elements select = document.select("div.r").select("a[href]");
for (Element element : select) {
kswListModel = new FictionModel();
kswListModel.title = element.text();
kswListModel.detailUrl = element.attr("abs:href");
kswListModel.type = TYPE_ADD;
list.add(kswListModel);
}
}
示例6: 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);
}
示例7: initPush
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
* 获取热门小说
*/
private void initPush(List<FictionModel> list) {
FictionModel kswModel;
Elements select = document.select("div.r").eq(0).select("a[href]");
FictionModel hotTitle = new FictionModel();
hotTitle.title = TYPE_TITLE_HOT;
hotTitle.type = TYPE_TITLE;
list.add(hotTitle);
for (Element element : select) {
kswModel = new FictionModel();
kswModel.title = element.text();
kswModel.detailUrl = element.attr("abs:href");
kswModel.type = TYPE_HOT;
list.add(kswModel);
}
initCenterHeader(list);
}
示例8: getNextPage
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Document getNextPage(Document doc) throws IOException {
// Find next page
String nextUrl = "";
Element elem = doc.select("div.bg-white > ul.pagination > li > a").last();
if (elem == null) {
throw new IOException("No more pages");
}
nextUrl = elem.attr("href");
// We use the global lastPage to check if we've already ripped this page
// and is so we quit as there are no more pages
if (nextUrl.equals(lastPage)) {
throw new IOException("No more pages");
}
lastPage = nextUrl;
// Sleep for half a sec to avoid getting IP banned
sleep(500);
return Http.url(nextUrl).get();
}
示例9: replace
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private static void replace(Elements elements, String attrName) {
String cdnDomain = Jboot.config(JbootRenderConfig.class).getCdn();
Iterator<Element> iterator = elements.iterator();
while (iterator.hasNext()) {
Element element = iterator.next();
if (element.hasAttr("cdn-exclude")) {
continue;
}
String url = element.attr(attrName);
if (StringUtils.isBlank(url) || !url.startsWith("/") || url.startsWith("//")) {
continue;
}
url = cdnDomain + url;
element.attr(attrName, url);
}
}
示例10: getURLsFromPage
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<>();
// Page contains images
logger.info("Look for images.");
for (Element thumb : page.select("img")) {
logger.info("Img");
if (super.isStopped()) break;
// Find thumbnail image source
String image = null;
String img_type = null;
String src = null;
if (thumb.hasAttr("typeof")) {
img_type = thumb.attr("typeof");
if (img_type.equals("foaf:Image")) {
logger.debug("Found image with " + img_type);
if (thumb.parent() != null &&
thumb.parent().parent() != null &&
thumb.parent().parent().attr("class") != null &&
thumb.parent().parent().attr("class").equals("aimage-center")
)
{
src = thumb.attr("src");
logger.debug("Found url with " + src);
if (!src.contains("zizki.com")) {
} else {
imageURLs.add(src.replace("/styles/medium/public/","/styles/large/public/"));
}
}
}
}
}
return imageURLs;
}
示例11: rip
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public void rip() throws IOException {
logger.info("Retrieving " + this.url);
Document doc = Http.url(url).get();
Element iframe = doc.select("iframe").first();
String iframeSrc = iframe.attr("src");
if (iframeSrc != null) {
doc = Http.url("http://www.yuvutu.com" + iframeSrc).get();
} else {
throw new IOException("Could not find iframe code at " + url);
}
Elements script = doc.select("script");
if (script.size() == 0) {
throw new IOException("Could not find script code at " + url);
}
Pattern p = Pattern.compile("file: \"(.*?)\"");
for (Element element : script) {
Matcher m = p.matcher(element.data());
if (m.find()){
String vidUrl = m.group(1);
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
}
}
waitForThreads();
}
示例12: linkTraversal
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private void linkTraversal(Elements links) throws IOException {
// Iterate through links
for(Element link: links) {
String absoluteLink = link.attr("abs:href");
String solution = java.net.URLDecoder.decode(absoluteLink, "UTF-8"); // Convert link to absolute link and decode it with url decoder
String fileName = solution.substring(solution.indexOf("challenges/") + "challanges/".length(), solution.indexOf("?")); // Extract file name from url
solution = solution.substring(solution.indexOf("\n")); // after the first new line, rest of the link is the solution
Document solutionPage = getInstructionDocument(absoluteLink);
String instructionString = getInstructions(solutionPage); // get the instructions as a string
callWriter(fileName, instructionString, solution);
}
}
示例13: getId
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Nonnull
@Override
public String getId() throws ParsingException {
try {
Element element = doc.getElementsByClass("yt-uix-subscription-button").first();
if (element == null) element = doc.getElementsByClass("yt-uix-subscription-preferences-button").first();
return element.attr("data-channel-external-id");
} catch (Exception e) {
throw new ParsingException("Could not get channel id", e);
}
}
示例14: getUrl
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public String getUrl() throws ParsingException {
try {
Element el = item.select("div[class*=\"yt-lockup-video\"").first();
Element dl = el.select("h3").first().select("a").first();
return dl.attr("abs:href");
} catch (Exception e) {
throw new ParsingException("Could not get web page url for the video", e);
}
}
示例15: getNextPage
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
@Override
public Document getNextPage(Document doc) throws IOException {
// Find next page
String nextUrl = "";
Element elem = doc.select("a.pg_next").first();
nextUrl = elem.attr("href");
if (nextUrl.equals("") || nextUrl.equals("#")) {
throw new IOException("No more pages");
}
return Http.url(nextUrl).get();
}