Using jsoup library I am trying to get the href of an <a> element which contains specified text each time.
Example:
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.select.Elements
String url = "https://www.website.com/"
Document currentPageSource
currentPageSource = Jsoup.connect(url).get()
Elements wElements = currentPageSource.select('a[class="class-name"]:contains('+desiredText+')')
if(wElements) {
// ...
}
- The variable
desiredTextis a “global” variable which changes every time that function called.
The problem is when desiredTextcontains single quote character!!! For example, if desiredText is I am here it “works” fine. But if desiredText is I'm here i get this error: Did not find balanced marker at 'I'.
I tried to use desiredText variable with double-quoted, triple-single-quoted or triple-double-quoted but I get the same error.
Any idea how I’ll fix this?
PS: I have to use jsoup because I can see <a> element only through “View Page Source” and not through “Inspector” tool.
Thank you for your time!!!
