我试图使用if语句,但是它没有做我想要的事情。
我试图使用jsoup从html源代码中提取所有图像,但是html中的某些项目没有图像,因此其中没有(img)标记,所以这里是我使用的if语句
.price-border:after {
left: 100%;
transform: translateX(-55%) rotate(45deg);
}
所以在循环过程中找到循环if(https://ssli)然后提取当前找到的
Elements imagess = doc.select("img[src$=.jpg]");
//Elements imagess = doc.select("img");
for (Element table : doc.select("div[class=listing-content]")) {
// Identify all the table row's(tr)
for (Element row : table.select("div:gt(0)")) {
HashMap<String, String> map = new HashMap<String, String>();
String[] imgg = new String[imagess.size()];
ArrayList products = new ArrayList();
for (int i = 0; i < imagess.size(); i++)
if (imagess.toString().contains("https://ssli")) {
imgg[i] = imagess.get(i).attr("src");
} else {
imgg[i] = "https://afs.googleusercontent.com/gumtree-com/noimage_thumbnail_120x92_v2.png";
}
其他,请添加空白图片网址imgg[i] = imagess.get(i).attr("src");
这里是从页面中提取的html代码的一部分是有更多图像而没有图像标记
imgg[i] = "https://afs.googleusercontent.com/gumtree-com/noimage_thumbnail_120x92_v2.png";
因为你可以使用带有图片的html标签列表 - 缩略图而没有它没有它。
也似乎是
<div class="listing-content">
<h2 class="listing-title" itemprop="name">
Faulty Xbox 36
</h2>
<p class="listing-description
hide-fully-to-m"
itemprop="description">
Turns on but tray broken so can't load games .
Sold as seen
</p>
<ul class="listing-attributes inline-list hide-fully-to-m">
</ul>
<div class="listing-location" itemscope itemtype="http://schema.org/Place">
<span class="truncate-line" itemprop="name">
Sunbury-on-Thames, Surrey
</span>
</div>
<strong class="listing-price txt-emphasis"
itemprop="price">£20</strong>
<strong class="listing-posted-date txt-normal truncate-line" itemprop="adAge">
<span class="hide-visually">Ad posted </span>
11 mins ago
</strong>
</div>
</a>
<span class="save-ad listing-save-ad"
data-savead="channel:savead-1131358978">
<span class="hide-visually">Save this ad</span>
<span class="icn-star iconu-m txt-quaternary" aria-hidden="true"></span>
</span>
</article>
</li>
<li>
<article class="listing-maxi" itemscope itemtype="http://schema.org/Product" data-q=ad-1131358703>
<a class="listing-link" href="/p/video-games/xbox-360-cod-/1131358703" itemprop="url">
<div class="listing-side">
<div class="listing-thumbnail ">
<img src="" data-lazy="https://ssli.ebayimg.com/00/s/ODAwWDYwMA==/z/uFgAAOSwMmBV4eSL/$_26.JPG"
alt="" itemprop="image"
class="hide-fully-no-js"/>
<noscript>
<img src="https://ssli.ebayimg.com/00/s/ODAwWDYwMA==/z/uFgAAOSwMmBV4eSL/$_26.JPG" alt="" itemprop="image"/>
</noscript>
</div>
<div class="listing-meta">
<ul class="inline-list txt-center">
<li>1<span class="hide-visually"> images</span>
<span class="icn-camera txt-quaternary" aria-hidden="true"></span>
</li>
</ul>
</div>
</div>
<div class="listing-content">
<h2 class="listing-title" itemprop="name">
Xbox 360 cod
</h2>
<p class="listing-description truncate-paragraph
hide-fully-to-m"
itemprop="description">
Call of duty advanced warfare £12
Call of duty modern warfare 3 £5
Black ops 2 SOLD
Both for £15
No offers
</p>
<ul class="listing-attributes inline-list hide-fully-to-m">
</ul>
<div class="listing-location" itemscope itemtype="http://schema.org/Place">
<span class="truncate-line" itemprop="name">
Norwich, Norfolk
</span>
</div>
<strong class="listing-price txt-emphasis"
itemprop="price">£1</strong>
<strong class="listing-posted-date txt-normal truncate-line" itemprop="adAge">
<span class="hide-visually">Ad posted </span>
13 mins ago
</strong>
</div>
</a>
<span class="save-ad listing-save-ad"
data-savead="channel:savead-1131358703">
<span class="hide-visually">Save this ad</span>
<span class="icn-star iconu-m txt-quaternary" aria-hidden="true"></span>
</span>
</article>
</li>
<li>
<article class="listing-maxi" itemscope itemtype="http://schema.org/Product" data-q=ad-1131358320>
<a class="listing-link" href="/p/xbox-one/xbox-one-w-kinect-5-games-forza-horizon-2-incl.-blu-ray-2-controllers-2-charger-cables-1-mic/1131358320" itemprop="url">
<div class="listing-side">
<div class="listing-thumbnail ">
<img src="" data-lazy="https://ssli.ebayimg.com/00/s/OTYwWDk2MA==/z/n4AAAOSwLVZV4eQ1/$_26.JPG"
alt="" itemprop="image"
class="hide-fully-no-js"/>
<noscript>
<img src="https://ssli.ebayimg.com/00/s/OTYwWDk2MA==/z/n4AAAOSwLVZV4eQ1/$_26.JPG" alt="" itemprop="image"/>
</noscript>
</div>
<div class="listing-meta">
<ul class="inline-list txt-center">
<li>8<span class="hide-visually"> images</span>
<span class="icn-camera txt-quaternary" aria-hidden="true"></span>
</li>
</ul>
</div>
</div>
其他地方的代码不解决不确定原因,它在找到时打印出来并且没有找到
if (imagess.get(i).toString().contains("https://ssli")){
imgg[i] = imagess.get(i).attr("src");
} else {
imgg[i] = "https://afs.googleusercontent.com/gumtree-com/noimage_thumbnail_120x92_v2.png";
}
当发现这样时,返回
for (int j = 0; j < hrefElements.size(); j++) {
System.out.println("title: " + titlee[j]);
System.out.println("description: " + description[j]);
System.out.println("distance: " + distance[j]);
System.out.println("posted: " + posted[j]);
System.out.println("price: " + pricee[j]);
System.out.println("meta: " + listingmeta[j]);
System.out.println("link: " + linkss[j]);
System.out.println("img-link: " + imgg[j]);
}
return products;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
否则找不到的时候
System.out.println("img-link: " + "https://ssli.ebayimg.com/00/s/OTYwWDk2MA==/z/n4AAAOSwLVZV4eQ1/$_26.JPG");
空白而不是空白我希望它在其他地方添加我的自定义链接
答案 0 :(得分:1)
Dim filepath as string = "c:\mydirecotory\mysubdirectory\myfile.wav"
auPlayer.InnerHtml = "<source src='" + filepath + "' type='audio/wav'/>"
似乎是某种集合。而不是对集合进行字符串化:
imagess
您可能想要检查集合的元素:
if (imagess.toString().contains("https://ssli"))