本文整理匯總了Java中org.jsoup.nodes.Element.hasAttr方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.hasAttr方法的具體用法?Java Element.hasAttr怎麽用?Java Element.hasAttr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.hasAttr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getURLsFromPage
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("#gallery img")) {
if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) {
continue;
}
String image = thumb.attr("src");
image = image.replaceAll(
"http://x.*.fap.to/images/thumb/",
"http://fap.to/images/full/");
image = image.replaceAll("w[0-9]+-h[0-9]+/", "");
imageURLs.add(image);
if (isThisATest()) {
break;
}
}
return imageURLs;
}
示例2: ripUserAccount
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
/**
* Rips all albums in an imgur user's account.
* @param url
* URL to imgur user account (http://username.imgur.com)
* @throws IOException
*/
private void ripUserAccount(URL url) throws IOException {
logger.info("Retrieving " + url);
sendUpdate(STATUS.LOADING_RESOURCE, url.toExternalForm());
Document doc = Http.url(url).get();
for (Element album : doc.select("div.cover a")) {
stopCheck();
if (!album.hasAttr("href")
|| !album.attr("href").contains("imgur.com/a/")) {
continue;
}
String albumID = album.attr("href").substring(album.attr("href").lastIndexOf('/') + 1);
URL albumURL = new URL("http:" + album.attr("href") + "/noscript");
try {
ripAlbum(albumURL, albumID);
Thread.sleep(SLEEP_BETWEEN_ALBUMS * 1000);
} catch (Exception e) {
logger.error("Error while ripping album: " + e.getMessage(), e);
}
}
}
示例3: 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;
}
示例4: 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);
}
}
示例5: retrieveLinksFromHTML
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private ArrayList<String> retrieveLinksFromHTML(Elements body) {
ArrayList<String> linkRes = new ArrayList<String>();
Elements links = body.select("div.g");
links = links.select("a[href]");
for (Element link : links){
if (!link.hasClass("_Fmb ab_button") &&
! link.hasClass("fl") &&
! link.hasClass("bia") &&
! link.hasClass("duf3") &&
! link.hasClass("iu-card-header") &&
! link.hasAttr("data-rtid") &&
! link.hasAttr("data-ved")) {
String toCheck = link.attr("href");
if (!linkRes.contains(toCheck)) {
linkRes.add(toCheck);
}
}
}
return linkRes;
}
示例6: processMessageViews
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private void processMessageViews(URL url, String html)
{
Document document = Jsoup.parse(html);
Elements elements = document.select("user-container");
for (Element e : elements)
{
Elements link = e.select("a");
Element signature = new Element("");
for (Element e1 : link)
{
if (e1.hasAttr("class") && e1.attr("class").equals("signature"))
{
signature = e1;
break;
}
}
}
}
示例7: getInternalVideoUrl
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private String getInternalVideoUrl(String url) {
WriteLog.appendLog("getInternalVideoUrl(" + url + ") called");
String lVideoUrl = "";
try {
Document docdata = Jsoup.connect(url).userAgent(getUserAgent())
.referrer(getServerUrl())
.timeout(Parser.getParseTimeOut()).get();
Elements scriptEles = docdata.select("div[class=videocontent]").select("video").select("source");
Element script = null;
String text = "";
if (scriptEles != null) {
for (int i = 0; i < scriptEles.size(); i++) {
script = scriptEles.get(i);
if (script != null && script.hasAttr("src"))
lVideoUrl = script.attr("src");
}
}
} catch (IOException e) {
WriteLog.appendLog(Log.getStackTraceString(e));
}
return lVideoUrl;
}
示例8: getEstreamToVideo
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
public String getEstreamToVideo(String url) {
String lVideoUrl = "";
try {
Document docdata = Jsoup.connect(url).userAgent(mUserAgent)
.referrer("http://www.google.com")
.timeout(Parser.getParseTimeOut()).get();
Elements eles = null;
if (!url.contains("embed")) {
eles = docdata.select("div[class=leftcol]").select("iframe");
if (eles != null && !eles.isEmpty()) {
url = eles.get(0).attr("src");
return getMP4UploadComVideo(url);
}
} else {
eles = docdata.select("video").select("source");
for (Element element : eles) {
if (element.hasAttr("type") && element.attr("type").startsWith("video")) {
return element.attr("abs:src");
}
}
}
} catch (IOException e) {
WriteLog.appendLog(Log.getStackTraceString(e));
}
return lVideoUrl;
}
示例9: getNextPage
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public Document getNextPage(Document doc) throws IOException {
Element pagination = doc.select("div.pagination").first();
if (pagination.hasAttr("next-page-url")) {
String nextPage = pagination.attr("abs:next-page-url");
// Only logged in users can see past page 25
// Trying to rip page 26 will throw a no images found error
if (!nextPage.contains("page=26")) {
logger.info("Getting next page: " + pagination.attr("abs:next-page-url"));
return Http.url(pagination.attr("abs:next-page-url")).cookies(cookies).get();
}
}
throw new IOException("No more pages");
}
示例10: rip
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public void rip() throws IOException {
int index = 0;
logger.info("Retrieving " + this.url);
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
if (albumDoc == null) {
albumDoc = Http.url(url).get();
}
for (Element thumb : albumDoc.select("#galleryImages > a > img")) {
if (!thumb.hasAttr("src")) {
continue;
}
String image = thumb.attr("src");
image = image.replace(
"/thumbs/",
"/");
index += 1;
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
if (isThisATest()) {
break;
}
}
waitForThreads();
}
示例11: getURLsFromPage
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<>();
Pattern p; Matcher m;
//select all album thumbnails
for (Element span : page.select(".NA_articleGallery span")) {
if (!span.hasAttr("style")) {
continue;
}
String style = span.attr("style").trim();
p = Pattern.compile("background-image: url\\((.*list_thumb_inbox.*)\\);", Pattern.CASE_INSENSITIVE);
m = p.matcher(style);
if (m.find()) {
String imgUrl = m.group(1);
if (imgUrl.startsWith("//")) {
imgUrl = "http:" + imgUrl;
}
if (imgUrl.startsWith("/")) {
imgUrl = "http://" + this.url.getHost() + imgUrl;
}
//convert thumbnail url into fullsize url
imgUrl = imgUrl.replace("list_thumb_inbox","xlarge");
// Don't download the same URL twice
if (imageURLs.contains(imgUrl)) {
logger.debug("Already attempted: " + imgUrl);
continue;
}
imageURLs.add(imgUrl);
if (isThisATest()) {
break;
}
}
if (isStopped()) {
break;
}
}
return imageURLs;
}
示例12: removeUselessAttributes
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
public static void removeUselessAttributes(Element element) {
for (Element child : element.getAllElements()) {
if (child.hasAttr("style"))
child.removeAttr("style");
}
}
示例13: getInternalVideoUrlAniUploader
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private String getInternalVideoUrlAniUploader(String url) {
WriteLog.appendLog("getInternalVideoUrlAniUploader(" + url + ") called");
String lVideoUrl = "";
try {
Document docdata = Jsoup.connect(url).userAgent(getUserAgent())
.referrer(getServerUrl())
.timeout(Parser.getParseTimeOut()).get();
Elements scriptEles = docdata.select("div[class=dowload]").select("a");
Element script = null;
String text = "";
String providerUrl = "";
if (scriptEles != null) {
for (int i = 0; i < scriptEles.size(); i++) {
script = scriptEles.get(i);
if (script != null && script.hasAttr("href")) {
providerUrl = script.attr("href");
lVideoUrl = getVideoFromProvider(providerUrl);
if (!TextUtils.isEmpty(lVideoUrl))
break;
}
}
}
} catch (IOException e) {
WriteLog.appendLog(Log.getStackTraceString(e));
}
return lVideoUrl;
}
示例14: readDesign
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
Attributes attr = design.attributes();
if (design.hasAttr("time-zone")) {
setZoneId(ZoneId.of(DesignAttributeHandler.readAttribute("end-date", attr, String.class)));
}
if (design.hasAttr("time-format")) {
setTimeFormat(TimeFormat.valueOf(
"Format" + design.attr("time-format").toUpperCase()));
}
if (design.hasAttr("start-date")) {
setStartDate(
ZonedDateTime.ofInstant(DesignAttributeHandler.readAttribute("start-date", attr, Date.class)
.toInstant(), getZoneId()));
}
if (design.hasAttr("end-date")) {
setEndDate(
ZonedDateTime.ofInstant(DesignAttributeHandler.readAttribute("end-date", attr, Date.class)
.toInstant(), getZoneId()));
}
}
示例15: getSrc
import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private String getSrc(Element img) {
String src = "";
if (img.hasAttr("src")) {
src = img.attr("src");
} else if (img.hasAttr("data-src")) {
src = img.attr("data-src");
} else if (img.hasAttr("data-lazy-src")) {
src = img.attr("data-lazy-src");
}
return src;
}