page_source method is used retrieve the page source of the webpage the user is currently accessing. The main use of this method to find something in the page source like finding any data or keyword.
Page source : The source code/page source is the programming behind any webpage.
Syntax :
driver.page_source
Argument :
It takes no argument.
Return value :
It return the page source in string format.
# importing webdriver from selenium from selenium import webdriver # Here Chrome will be used driver = webdriver.Chrome() # URL of the website # Opening the URL driver.get(url) # Getting current URL source code get_source = driver.page_source # Printing the URL print(get_source) |
Output : This code will print the source code of the “https://www.geeksforgeeks.org/”.
Code 2. When no web page is opened.
# importing webdriver from selenium from selenium import webdriver # Here Chrome will be used driver = webdriver.Chrome() # Getting current URL source code get_source = driver.page_source # Printing the URL print(get_source) |
Output :

Recommended Posts:
- How to use close() and quit() method in Selenium Python ?
- Python - find_element_by_id() method in Selenium
- Navigating links using get method - Selenium Python
- find_element_by_name() driver method - Selenium Python
- find_element_by_xpath() driver method - Selenium Python
- find_element_by_link_text() driver method - Selenium Python
- find_element_by_partial_link_text() driver method - Selenium Python
- find_element_by_tag_name() driver method - Selenium Python
- find_element_by_class_name() driver method - Selenium Python
- find_element_by_id() driver method - Selenium Python
- find_element_by_css_selector() driver method - Selenium Python
- find_elements_by_name() driver method - Selenium Python
- find_elements_by_xpath() driver method - Selenium Python
- find_elements_by_link_text() driver method - Selenium Python
- find_elements_by_partial_link_text() driver method - Selenium Python
- find_elements_by_tag_name() driver method - Selenium Python
- find_elements_by_class_name() driver method - Selenium Python
- find_elements_by_css_selector() driver method - Selenium Python
- is_selected() element method - Selenium Python
- is_displayed() element method - Selenium Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

