Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the entire web page source using Selenium WebDriver in python [duplicate]

I am using Selenium WebDriver in python, and I would like to retrieve in a variable the entire page source of the web page (something like the right click option that many web browsers provide to get the page source).

Any help is appreciated

like image 255
sdmythos_gr Avatar asked Feb 18 '16 16:02

sdmythos_gr


People also ask

What is the use of getPageSource ()?

getPageSource() is method of WebDriver class. So driver. getPageSource() returns source code of the page which stored as string. contains is method of a String class to check if a string contains in another string.

How can the Webdriver imitate the double click?

We can perform double click on elements in Selenium with the help of Actions class. In order to perform the double click action we will use moveToElement() method, then use doubleClick() method. Finally use build().


1 Answers

Your WebDriver object should have a page_source attribute, so for Firefox it would look like

from selenium import webdriver
driver = webdriver.Firefox()
driver.page_source
like image 98
nathan.medz Avatar answered Oct 20 '22 11:10

nathan.medz