How can i parse HTML page in Android with js results? The main problem is that if i simply use Jsoup.connect() method the Document object doesn't contain js results, because js needs some time for running. Is it possible to delay connection?
1 Answer
As already mentioned in the comments, JSOUP does not run any JavaScript. For that you would need a JavaScript Interpreter.
Since you mentioned that the page you are wanting to read takes some time to render, it seems clear that you actually need to run the JavaScript to render the DOM.
However, if you look into the source code of the page you may be able to figure out how the JavaScript actually renders the page. I see two possibilities:
1) The JavaScript really just runs to dynamically render the page with information that is already loaded with the initial access. That frequently happens for modern websites that are able to send along all relevant data with the first access (aka isomorphic rendering). Here you may get the wanted information for data that is usually available in the website as JSON objects. You can extract the JSON and then parse this with a JSON parser.
2) The JavaScript actually loads some data asynchronously. IN that case you can identify these http requests and use JSOUP to get this data. Usually such data is in JSON format, so also in this case it may make sense to use A JSON parser to read out the relevant parts.
Jsoupdoesn't execute the JavaScript, waiting for the DOM to be ready is not the problem. You'll have to use something that has a JavaScript engine, something like Selenium or PhantomJS.Jsoupdoesn't have that.