public class Main {
public static void main(String[] args) {
List<Article> articleList = new ArrayList<>();
Document doc;
try {
doc = Jsoup.connect("https://vk.com/team").get();
Elements links = doc.getElementsByAttributeValue("class", "page_post_sized_thumbs clear_fix");
links.forEach(link -> {
Element url = link.child(0);
String a = url.attr("style");
Elements pngs = url.select(".jpg");
String v = pngs.text();
System.out.println(a);
articleList.add(new Article(v));
});
articleList.forEach(System.out::println);} catch (IOException e) { e.printStackTrace();}
}
}
class Article {
private String url;
public Article(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "Article{" +
"url='" + url + '\'' +
'}';
}
}
jsoupDocument = Jsoup.parse(pageSource);
jsoupElements = jsoupDocument.getElementsByAttributeValue("class",
"people_cell");
assertThat(jsoupElements.size(), greaterThan(0));
jsoupElements.forEach(link -> {
Element imgElement = link.getElementsByTag("img").get(0);
assertThat(imgElement, notNullValue());
// NOTE: url has empty string in html()
attributeValue = imgElement.attr("src");
assertThat(attributeValue, startsWith("https://"));
String url = attributeValue.replaceAll(".jpg?.*$", "");
articleList.add(new Article(url));
});
articleList.forEach(System.err::println);
Article{url='https://sun6-16.userapi.com/c628420/v628420404/e2ca/wKt7vWFzMOA'}
Article{url='https://pp.userapi.com/c841228/v841228591/113bc/UDcryzU7E6I'}
Article{url='https://pp.userapi.com/c9267/u00190/e_d11db660'}