1

I'm trying to retrieve the links from this html table using selenium, since the website uses JavaScript. The problem is, that while I can get the text values, I am still unable to select the links that will be used to continue the scrapping.

<table cellspacing="0" cellpadding="5" align="Center" border="0" id="SearchResultsGrid" width="600">
<tr align="Center" valign="Middle">
<td align="Left"><font face="Verdana" size="1">id1</font></td><td><font face="Verdana" size="1"><a href="http.url.com" target="_self">"name1</a></font></td><td align="Center"><font face="Verdana" size="1">prop1</font></td>
<td align="Left"><font face="Verdana" size="1">id2</font></td><td><font face="Verdana" size="1"><a href="http.url2.com" target="_self">name2</a></font></td><td align="Center"><font face="Verdana" size="1">prop2</font></td>
</tr>
</table>

My code is:

table = driver.find_element_by_id("SearchResultsGrid")
links = table.find_elements_by_tag_name('a')
for link in links:
    print(link.text)

have also tried to use table.find_element_by_xpath() to no avail..

0

1 Answer 1

1

Found the solution for my question:

table = driver.find_element_by_id("SearchResultsGrid")
links = table.find_elements_by_tag_name('a')
for link in links:
    print(link.get_attribute("href"))
    driver.get(link.get_attribute("href"))

The key was using the get_attribute("href") method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.