Related Articles

Related Articles

Python | page_source method in Selenium
  • Last Updated : 06 Mar, 2020

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.

Code 1.

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output : This code will print the source code of the “https://www.geeksforgeeks.org/”.

Code 2. When no web page is opened.

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :