I have a HTML code which looks like this.
<html><head><meta http-equiv="refresh" content="0;url=http://www.abc.com/event"/></head></html>
I want to use JSoup to parse this HTML and get the url value. How can I do this?
You need to parse the content by yourself. Something like this:
Elements refresh = document.head().select("meta[http-equiv=refresh]");
if (!refresh.isEmpty()) {
Element element = refresh.get(0);
String content = element.attr("content");
// split the content here
Pattern pattern = Pattern.compile("^.*URL=(.+)$", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(content);
if (matcher.matches() && matcher.groupCount() > 0) {
String redirectUrl = matcher.group(1);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With