I have the following HTML page. I want to get all the links inside a specific div. Here is my HTML code:
As per the HTML you have shared to get the list of all the links that are present on the rec_view
div you can use the following code block :
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32\chromedriver.exe')
driver.get('https://www.testurl.com/page/123/')
elements = driver.find_elements_by_css_selector("div.rec_view a")
for element in elements:
print(element.get_attribute("href"))
Note : As you need to collect all the href attributes from the div tag so instead of find_element_*
you need to use find_elements_*
. Additionally, >
refers to immediate <a>
child node where as you need to traverse all the <a>
child nodes so the desired css_selector
will be div.rec_view a