Java: Extract all links with a specific word in them using JSoup?

Perhaps this is a fuzzy question, so here is the code and explanation:

    Document doc = Jsoup.parse(exampleHtmlData);

    Elements certainLinks = doc.select("a[href=google.com/example/]");

The StringHtmlData example contains parsed HTML source from a specific site. There are many links on this site that direct the user to google. A few examples:

http://google.com/example/hello 
http://google.com/example/certaindir/anotherdir/something
http://google.com/anotherexample

I want to extract all links containing google.com/example/ into a link using the doc.select function. How to do it with JSoup?

+5
source share
1 answer

You can reference SelectorSyntax .

Document doc = Jsoup.parse(exampleHtmlData);
Elements certainLinks = doc.select("a[href*=google.com/example/]");
+9
source

All Articles