📅  最后修改于: 2023-12-03 14:54:27.270000             🧑  作者: Mango
In this guide, we will learn how to use Selenium in Python to print the URL of a webpage. Selenium is a powerful tool for web scraping and automated testing. By using Selenium, we can automate the process of opening a webpage and extracting its URL.
Before we begin, make sure you have the following:
pip install selenium
)Follow the steps below to print the URL of a webpage using Selenium in Python:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://example.com")
print(driver.current_url)
driver.quit()
Here is a complete example that demonstrates how to print the URL of a webpage using Selenium in Python:
from selenium import webdriver
# Set up the WebDriver
driver = webdriver.Chrome()
# Open the webpage
driver.get("https://example.com")
# Print the URL
print(driver.current_url)
# Close the WebDriver
driver.quit()
Using the above guide, you can easily print the URL of a webpage using Selenium in Python. Selenium provides a convenient way to automate web interactions and extract information from websites.