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
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.
.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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With