I have a webpage that creates a table using Javascript. I am currently using JSoup in my Java project to parse a web page. By the way, JSoup cannot run Javascript, so the table is not created, and the source of the web page is incomplete. How to include HTML code generated by this script to parse its contents using JSoup? Can you give a simple example? Thank!
Example webpage:
<!doctype html>
<html>
<head>
<title>A blank HTML5 page</title>
<meta charset="utf-8" />
</head>
<body>
<script>
var table = document.createElement("table");
var tr = document.createElement("tr");
table.appendChild(tr);
document.body.appendChild(table);
</script>
<p>First paragraph</p>
</body>
</html>
The output should be:
<!DOCTYPE html>
<html>
<head>
<title>
A blank HTML5 page
</title>
<meta charset="utf-8"></meta>
</head>
<body>
<script>
var table = document.createElement("table");
var tr = document.createElement("tr");
table.appendChild(tr);
document.body.appendChild(table);
</script>
<table>
<tr></tr>
</table>
<p>
First paragraph
</p>
</body>
</html>
By the way, JSoup does not include the table tag because it cannot execute Javascript. How can i achieve this?
source
share