这是我的Jsoup代码
try {
Document document = Jsoup.connect("https://www.aliexpress.com/category/200214036/women-watches.html?spm=2114.search0103.3.7.765d221bi3J3Io&site=glo&g=y").get();
Elements titleElement = document.select("div.item > div.has-sku-image > a");
Elements imageElement = document.select("div.item > div.img > div.pic > a.picRind > img");
Elements priceElement = document.select("div.item > div.info > span.price");
int i = 0;
String imagesSource[] = new String[imageElement.size()];
String titlesSource[] = new String[titleElement.size()];
String pricesSource[] = new String[titleElement.size()];
int j = imageElement.size();
for(i=0; i <= j; i++){
//check if src value is empty, which is true if the src attr does not exist
if(!imageElement.get(i).attr("abs:src").isEmpty()){
imagesSource[i] = imageElement.get(i).attr("abs:src");
titlesSource[i] = titleElement.get(i).attr("title");
pricesSource[i] = priceElement.get(i).text();
System.out.println(imagesSource[i]);
System.out.println(titlesSource[i]);
System.out.println(pricesSource[i]);
}
else{
imagesSource[i] = imageElement.get(i).attr("abs:image-src");
titlesSource[i] = titleElement.get(i).attr("title");
System.out.println(imagesSource[i]);
System.out.println(titlesSource[i]);
System.out.println(pricesSource[i]);
}
}
} catch (IOException ex) {
Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex);
}
所有这些都是好的价格不会出现在所有人面前。前6个有价格,但其他价格无效。
为什么会这样?所有值都具有相同的类别。
答案 0 :(得分:0)
你错过了
fold
在pricesSource[i] = priceElement.get(i).text();
部分。