I have written a python(version:3.4.3) script in which I am using BeautifulSoup to fetch the contents from a html page,in that page there is a paragraph tag and initially there is no content in it,but I have added an event listener on the window which will add some content in that paragraph tag.
Python script:
from bs4 import BeautifulSoup
import requests
import os
from urllib.parse import urljoin
def url():
res = requests.get('http://localhost:8000/a.html')
soup = BeautifulSoup(res.text);
print(soup.p.get_text());
Html file:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "It worked";
}
window.addEventListener('load',getLocation);
</script>
</body>
</html>
The problem is that the last line of the python script prints a blank line instead of the data which I dynamically added in that paragraph.
I think the problem is with the addEventListener as I am not actually opening the page.
Could anyone please provide an alternative way to fetch the content from a tag in which the content is added by some javascript code(using beautifulsoup)?