I’m trying to scrape an RSS feed located here.
At the moment I’m just trying to wrap my head around JSoup, so the following code is merely proof of concept (or an attempt at it, at least).
public static void grabShakers(String url) throws IOException {
doc = Jsoup.connect(url).get();
desc = doc.select("title");
links = doc.select("link");
price = doc.select("span.price");
}
It grabs the title of each item perfectly. The output of each link is simply ten repeated closing link tags and it never finds any prices. I thought perhaps the CDATA was the issue, so I converted doc to html, stripped out the comments using .replace, and then converted it back to a Document for parsing to no avail. Any insight would be greatly appreciated.
The following code is what I’m using to print out each element:
for (Element src : price) {
System.out.println(src);
}
There are two Problems with that feed:
<link />..actual link..instead of full link tagSolution:
Note 1: Workaround for the link; select the (empty)
linktag and get the text of next Node (= TextNode with the actual link).Note 2: Workaround for price; select the
descriptiontag, unescape the html, parse it and select the price. For unescaping i used StringEscapeUtils.unescapeHtml4() from Apache Commons Lang.Output:
(using link from above)