I want to get the source code of HTML document which is inside an HTML tag which is generated after some JavaScript and store it in a variable. Here, the HTML tag is <iframe>
and it contains a variable kind of something that looks like #document
and when I expand this, I get an HTML document which looks something like <!DOCTYPE html> <html>...</html>
To summarize:
<iframe src="https://www.XXXXXX.com/" allow="autoplay; fullscreen" frameborder="no" scrolling="no" allowfullscreen="yes" style="width: 100%; height: 100%;">
#document
<!DOCTYPE html>
<html>...</html> // a whole new HTML document
</iframe>
I want to store all the content of this HTML document as a string in python
What I have done:
driver.find_element_by_xpath('/path/to/iframe/tag').get_attribute('innerHTML')
but, this just returns an empty string. Also, I have checked if it is working with BeautifulSoup
html = driver.execute_script("return document.body.innerHTML")
soup = BeautifulSoup(html, 'html5lib')
print(soup.prettify())
but, this also isn't working
NOTE: I run these test only after the script is executed, also, I guess the problem seems to be with the #document
thing