0

This will print out 10+ links, how do I limit it to only fetch the first 3 links?

def getlinks(self):
        self.driver.get('https://www.youtube.com/results?search_query=iphone&sp=EgQIBRAB')

        the_links = self.driver.find_elements(By.ID, "video-title")
        sleep(5)

        for link in the_links:
            self.links.append(link.get_attribute('href'))

        for link in self.links:
            print(link)
1
  • you point directly to index positon of the link using : for link in self.links[:3] Commented Dec 29, 2021 at 6:36

1 Answer 1

2

Try for link in self.links[:3].

You can also use the equivalent expression for link in self.links[0:3].

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.