I am building a scraper in Python and want to call scripts, which are in a HTML code, like web browsers do while entering a website. Is it possible to run scripts from Python level on the HTML code?
The purpose is to get the same HTML code as in 'DOM Inspector' in web browser, not the code you can simply download with
requests.get("https://example.com")
or when you use 'View Source' mode...
Let's say I get the code:
<!DOCTYPE html>
<html>
<body>
<h1>The script element</h1>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>
If I run the script it will change the content of <p> element and results will be
<!DOCTYPE html>
<html>
<body>
<h1>The script element</h1>
<p id="demo">Hello JavaScript!</p>
</body>
</html>
So how can I run it and get the HTML code evaluated with all scripts from a page?
EDIT 1: I know the library "Selenium", but I am trying to solve my problem without using browser simulators, just Python and JavaScript...
Thanks in advance!