Answer the question
In order to leave comments, you need to log in
Why can't Jsoup parse the site?
Good day to all. I am studying Jsoup and want to parse a website page and then get links to ads from it:
https://auto.ru/sankt-peterburg/cars/bmw/5er/all/?...
In this way:
List<String> advertsURLs = new ArrayList<>();
Document doc;
System.out.println("start parsing Advs....");
try {
doc = Jsoup.connect(url) .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com").timeout(10*1000)
.get();
System.out.println(doc.text());
Elements elements = doc.getElementsByClass("ListingItemTitle-module__link");
System.out.println(elements.text());
for (Element e:elements) {
advertsURLs.add(e.attr("href"));
}
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < advertsURLs.size(); i++) {
System.out.println(advertsURLs.get(i));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question