Answer the question
In order to leave comments, you need to log in
How to parse (Jsoup) an already fully loaded VK feed?
How to force Jsoup to load / parse the VK feed to the end?
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 + '\'' +
'}';
}
}
Answer the question
In order to leave comments, you need to log in
No way. It will not work to get dynamic elements with a simple GET request. This requires Selenium, PhantomJS or some similar tools.
Yevgeny Tarnov is almost correct. Here's what I got after some minor tweaks.
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'}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question