I am using Selenium with Python and want to access the plain HTML source code before it is parsed and the DOM is modified by the browser. I do not want to use "driver.page_source" as it is giving me back the DOM after parsing and for example dynamically created elements are included. I know I could do a second request with for example requests but I am looking for a way to extract it without doing an additional request. Any ideas?
Asked
Active
Viewed 66 times
1 Answers
0
You can get the plain HTML source by using driver.get(f"view-source:{url}")
. Then get the body of the source using driver.find_element_by_tag_name('body').text

Mitchell Olislagers
- 1,758
- 1
- 4
- 10
-
Thanks for the suggestion but this is also performing a second request. I was hoping to do it in a single request. – parzel Jan 31 '21 at 09:53
-
No, that's not possitble. – Mitchell Olislagers Jan 31 '21 at 16:10