'Web Scraping Identify and Extract Hyperlink

HI I have the following script that extracts the name and address of each site but I want to be able to also extract the href for each site so that I link to the individual sites. Any suggestions?

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
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://order.marstons.co.uk/")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/div/div/div/div[2]/div'))
    ).find_elements_by_tag_name('a')
    for el in element:
        print("heading",  el.find_element_by_tag_name('h3').text)
        print("address", el.find_element_by_tag_name('p').text)
finally:
    driver.quit()


Solution 1:[1]

You mean like this?

print(el.get_attribute("href"))

You can get attribute of a element from this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul