Trying to find HREF from table with Selenium in Python

42 views Asked by At

Webscraping a table into an Excel-file. Its a "Dynamic" table per 10 rows.

All the data is placed into Excel correctly, But having issues with the HREF-data.

The issue i am facing is that some rows dont have a HREF. I am using the following Xpath:

map = driver.find_elements(By.XPATH,'//*[@id="table_1"]/tbody//td[12]/a')

To get the HREF:

.get_attribute("href")[30:].split(",%20")[0]
.get_attribute("href")[30:].split(",%20")[1]

Via above Xpath is can find every HREF, but in case of NO HREF in the row, the following HREF-data is placed into the row where NO HREF-data should be.

Tried the below (without the "/a") but it returns nothing.

map_test = driver.find_elements(By.XPATH, '//*[@id="table_1"]/tbody//td[12]') 

When below code is used, it returns the text content which is not what I need, but keeps the data where is should be.

.get_attribute("textContent")

Any idea how i can find the HREFs and keep the data in the rows where it should be?

0

There are 0 answers