java - Jsoup: Parsing html out of a piece of javascript -
does of know how html out of javascript onmouseover event jsoup? might sound vague, here is code:
<table onmouseover="showhoverinfo('', '<a href="somelink"><b>sometext</b>/a><br /> other text <br /> <a href="some other link"><b>some text</b></a>')"
and goes on. know, is: how html code out of showhoverinfo() method, using jsoup?
all appreciated.
you can find onmouseover
attribute via .attr()
, process obtained string (in example below use regex) parameter value want:
import java.util.regex.*; import org.jsoup.jsoup; import org.jsoup.nodes.*; public class jsoupgetattributeexample { public static void main(string[] args) { document doc = jsoup.parse("<html><body><div>example</div>" + "<table id='mytable' onmouseover=\"showhoverinfo('', '<a href=\\\'somelink\\\'><b>sometext</b>/a><br /> other text <br /> <a href=\\\'some other link\\\'><b>some text</b></a>')\" >" + " <tr>" + " <td>"+ " </td>"+ " </tr>" + "</table>" + "</body></html>"); element mytable = doc.getelementbyid("mytable"); string onmouseover = mytable.attr("onmouseover"); system.out.println("onmouseover attribute: "+onmouseover); /* string processing html (second) parameter */ string secondparameter = null; pattern p = pattern.compile("showhoverinfo\\('.*', '(.*?)'\\)"); matcher m = p.matcher(onmouseover); if (m.find()) { secondparameter = m.group(1); } system.out.println("\nhtml parameter: "+secondparameter); } }
output:
onmouseover attribute: showhoverinfo('', '<a href=\'somelink\'><b>sometext</b>/a><br /> other text <br /> <a href=\'some other link\'><b>some text</b></a>') html parameter: <a href=\'somelink\'><b>sometext</b>/a><br /> other text <br /> <a href=\'some other link\'><b>some text</b></a>
Comments
Post a Comment