Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python WebDriver how to print whole page source (html)

Tags:

I'm using Python 2.7 with Selenium WebDriver. My question is how to print whole page source with print method. There is webdriver method page_source but it returns WebDriver and I don't know how to convert it to String or just print it in terminal

like image 699
wmarchewka Avatar asked Dec 10 '14 22:12

wmarchewka


People also ask

How do I getText to full page in Selenium?

Mastering XPath and CSS Selector for Selenium To get the text of the visible on the page we can use the method findElement(By. tagname()) method to get hold of . Next can then use the getText() method to extract text from the body tag.


1 Answers

.page_source on a webdriver instance is what you need:

>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
>>> driver.get('http://google.com')
>>> print(driver.page_source)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" itemtype="http://schema.org/WebPage" itemscope=""><head><meta name="descri
...
:before,.vscl.vslru div.vspib{top:-4px}</style></body></html>
like image 146
alecxe Avatar answered Oct 02 '22 13:10

alecxe