有没有办法在硒中一个一个地单击多个按钮的列表?

Is there a way to click a list of multiple buttons, one by one, in selenium?

我是一名学生,正在 python 上使用 selenium 进行抓取项目。我正在尝试从多个格式相同的配置文件中抓取数据。有一个目录网站,其中包含指向所有配置文件的按钮,但我遇到的问题是能够一次单击每个按钮,因为它们的格式都相同。我的目标是能够在新选项卡中打开第一个 link,从该配置文件中抓取数据,然后关闭第一个配置文件的选项卡并继续第二个。我希望使这个过程可重复。这是我目前所拥有的:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(executable_path="MY PATH TO MY CHROME DRIVER")
driver.implicitly_wait(5)
driver.get("http://directory.bcsp.org")

buttons = driver.find_elements_by_link_text('View Profile')

如果您对我的问题有任何解决方案,请告诉我。谢谢:)

"body" 下页

"profile_count" 获取 link

".get_attribute('href')" 用于从 "View Profile" 按钮

中刮取 link

"temp"旧window中的信息不会切换到新window中,所以我们需要temp

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep

driver = webdriver.Edge()
driver.get("https://directory.bcsp.org/")
count = int(input("Count : "))

body = driver.find_element_by_xpath("//body") #
profile_count = driver.find_elements_by_xpath("//div[@align='right']/a")

while len(profile_count) < count: # Get links up to "count"
    body.send_keys(Keys.END)
    sleep(1)
    profile_count = driver.find_elements_by_xpath("//div[@align='right']/a")

for link in profile_count: # Calling up links
    temp = link.get_attribute('href') # temp for 
    driver.execute_script("window.open('');") # open new tab
    driver.switch_to.window(driver.window_handles[1]) # focus new tab
    driver.get(temp)
    #   you can do
    #   what you want
    #   to do here
    driver.close()
    driver.switch_to.window(driver.window_handles[0])
driver.close()