A
A
AntVlad2021-09-20 22:01:14
selenium
AntVlad, 2021-09-20 22:01:14

How to get the necessary links using Selenium?

How to choose links of the following type:

<a href="/foo/bar" target="_blank" rel="noopener" title="foo bar" 
itemprop="url" data-marker="item-title" 
class="link-link-MbQDP link-design-default-_nSbv title-root-j7cja iva-item-title-_qCwt title-listRedesign-XHq38 title-root_maxHeight-SXHes">
<h3 itemprop="name" 
class="title-root-j7cja iva-item-title-_qCwt title-listRedesign-XHq38 title-root_maxHeight-SXHes text-text-LurtD text-size-s-BxGpL text-bold-SinUO">Foo Bar/h3>
</a>

Tried with:
driver.find_element_by_partial_link_text('/foo/bar')

But it throws a NoSuchElementException error, although a manual search of the page's source code shows 130 occurrences.
PS As I understand it, class names are formed on the fly, so it's not an option.
PSS It turns out that either by the link property data-marker="item-title" or by the title property itemprop="name". But how to write a request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2021-09-21
@AntVlad

//a[@itemprop='url']

V
Vindicar, 2021-09-20
@Vindicar

> find_element_by_partial_link_text
I suspect this checks the innerText of the link, not its href. Search by attribute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question