我试图获取与this webpage上给定类名匹配的所有元素。我试过了,但奇怪的是,只有第一个出现了
from collections import defaultdict
import json
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import ElementClickInterceptedException
import time
driver = webdriver.Chrome(executable_path=r"C:\Programs\chromedriver.exe")
location = "https://docs.google.com/spreadsheets/d/1iLqEFRaHPYxpJKU05VXt3HUCQ2OQUAg8FfWlyFbvaXc/edit?usp=sharing"
location = "https://docs.google.com/forms/d/e/1FAIpQLSfzocEm6IEDKVzVGOlg8ijysWZyAvQur0NheJb_I_xozgKusA/viewform?usp=sf_link"
class_name = "freebirdFormviewerViewItemsItemItemTitle.exportItemTitle.freebirdCustomFont"
driver.get(location)
questions = driver.find_element_by_class_name(class_name)
print(questions.text)
find_element_by_class_name
返回单个元素。要获取所有元素,需要使用find_elements_by_class_name
,它将返回列表您的代码应该如下所示:
相关问题 更多 >
编程相关推荐