With Selenium the easiest case is:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='path to chromedriver')
driver.get("https://realpython.com/python-web-scraping-practical-introduction/")
print(driver.current_url)
The code also depends on what you want to get from the page.
Let's imagine you want to get Table of Contents.
For this you will need to wait for it to appear and to get elements text:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')
driver.get("https://realpython.com/python-web-scraping-practical-introduction/")
print(driver.current_url)
WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".article-body .toc li")))
toc = driver.find_elements_by_css_selector(".article-body .toc li")
for el in toc:
print(el.text)
driver.close()
driver.quit()
The output will be:
https://realpython.com/python-web-scraping-practical-introduction/
Scrape and Parse Text From Websites
Your First Web Scraper
Extract Text From HTML With String Methods
A Primer on Regular Expressions
Extract Text From HTML With Regular Expressions
Check Your Understanding
Your First Web Scraper
Extract Text From HTML With String Methods
A Primer on Regular Expressions
Extract Text From HTML With Regular Expressions
Check Your Understanding
Use an HTML Parser for Web Scraping in Python
Install Beautiful Soup
Create a BeautifulSoup Object
Use a BeautifulSoup Object
Check Your Understanding
Install Beautiful Soup
Create a BeautifulSoup Object
Use a BeautifulSoup Object
Check Your Understanding
Interact With HTML Forms
Install MechanicalSoup
Create a Browser Object
Submit a Form With MechanicalSoup
Check Your Understanding
Install MechanicalSoup
Create a Browser Object
Submit a Form With MechanicalSoup
Check Your Understanding
Interact With Websites in Real Time
Conclusion
Additional Resources