Working with Windows, Python 3 and Selenium/Chromedriver, I'm trying to figure out a way to save an element's data (text AND images) to an offline file for later viewing. Things I've tried:
1. Save page source to .html file
page_source = driver.page_source
with open("page.html", "w", encoding="utf-8") as file:
file.write(page_source)
Problem with this is, it only saves the text of the page, not the images, just empty image placeholders are rendered on the saved page, not the actual images.
2. Take screenshots of the entire page
page_width = driver.execute_script('return document.body.scrollWidth')
page_height = driver.execute_script('return document.body.scrollHeight')
driver.set_window_size(page_width, page_height)
driver.save_screenshot("page.png")
Problem here is, even though I'm defining the entire page height/width, only the visible section of the page is screenshot'd, not the entire page worth of data, so scrolling would need to be incorporated.
3. Use a "select all" type logic taken from this answer
This is kind of a hacky workaround, but could work, but kind of looking for a better solution.
4. Make use of pressing CTRL + S to save the page and assets for offline viewing
This was ok, but it downloads a bunch of stuff into a separate folder that is needed to render the entire page, which I don't think is necessary as I only want the stuff from one element on the page. Plus I'll be downloading several pages and I don't want separate folders of stuff for each page either.
So I'm wondering if there's a better way to save the text AND images of a page element, preferably to a html, docx, or pdf file type? I've seen various solutions on SO, but haven't found one that can do this so looking for some direction/steer me in the right direction. Thanks!