D
D
Denis2021-02-18 20:34:54
Python
Denis, 2021-02-18 20:34:54

Run for no more than 5 times?

driver.get("https://www.site.com/arr-c/")
try:
    for a in driver.find_elements_by_xpath('.//a'):
        print(a.get_attribute('href'))
except Exception  as err:
    print(err)

Using Selenium (python3) I go to the site and display all links in print. The essence of the question, can you display the first 5 links and end there? It seems like it's possible through range(), but I can't figure out how to organize it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-02-18
@denisskazikovlol

for a in driver.find_elements_by_xpath('.//a')[:5]:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question