browser.find_elements
时间: 2023-09-25 15:09:24 浏览: 97
如何通过三个小项目入门Python爬虫.pdf
browser.find_elements() is a method used in Selenium WebDriver to locate multiple elements in a web page based on a specified selector. It returns a list of all the matching elements on the page.
Syntax:
```
browser.find_elements(By.<selector_type>, "<selector_value>")
```
Example:
```
from selenium import webdriver
from selenium.webdriver.common.by import By
# Create an instance of the WebDriver
browser = webdriver.Chrome()
# Navigate to a webpage
browser.get("https://www.example.com")
# Find all the links on the page
links = browser.find_elements(By.TAG_NAME, "a")
# Print the text of each link
for link in links:
print(link.text)
# Close the browser
browser.quit()
```
In this example, we first create an instance of the Chrome WebDriver and navigate to a webpage. We then use the `find_elements()` method to find all the links on the page and store them in a variable called `links`. Finally, we loop through the links and print the text of each one.
阅读全文