我有一张如下表:
我正在尝试使用下面的 Selenium Web 驱动程序代码提取标题名称(突出显示),但我得到的输出如下None
:
!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
wd.get('https://www.deakin.edu.au/information-technology/staff-listing')
title = wd.find_elements_by_class_name('module__accordion--title')
for j in range(0,6): #Iterating through Titles i.e Profesor, Emeritus Professor....
for i in title[j].find_elements_by_tag_name('span'): #Retrieving the title names
i = i.get_attribute('text')
print(i)
这导致以下输出:
所以问题是为什么我得到 None 而不是 text ?
该代码也存在于下面的 Google Colab 链接中。
谷歌 Colab 链接:https ://colab.research.google.com/drive/1R9-hzor-lDXddOsNzr3qFc_0qodrbU6g ? usp = sharing
你可以使用i.text
或i.get_attribute('innerText')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句