无法使用 selenium webdriver 在 span 标签中提取文本名称

用户3046211

我有一张如下表:

在此处输入图片说明

我正在尝试使用下面的 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.texti.get_attribute('innerText')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Selenium Webdriver(java)在SPAN标记之间单击文本

如何通过Java使用Selenium Webdriver从下拉列表中提取firstselected选项的文本

使用Selenium WebDriver提取文本和Web链接

无法清除文本区域,无法使用Selenium WebDriver自动输入清晰和模糊的文本

如何使用Selenium Webdriver提取日期

如何使用Selenium WebDriver按名称查找文本输入?

如何使用Selenium WebDriver和Python提取元素内的文本?

如何使用Python Selenium Webdriver获取li内span的值?

如何在Python中使用Selenium Webdriver提取文本?

使用Selenium从<div>中的<span>获取文本

无法使用Python的Beautiful Soup从特定的span标签提取文本

如何使用带有Java的Selenium Webdriver从包含在多个span标签内的span元素中获取实际文本

Selenium WebDriver Java-无法从span标签获取动态文本

无法使用Selenium WebDriver从“选择列表”中找到名称

如何单击使用<span>标记为Selenium Webdriver创建的按钮

无法使用Selenium WebDriver在文本框中输入值

使用 selenium webdriver 从嵌套的 div 标签中获取文本

Selenium WebDriver 如何在 javascript 中验证来自 Span Tag 的文本

使用 Selenium WebDriver 按文本查找元素

无法使用 selenium webdriver 清除文本区域字段

在 Span 中使用 selenium PhantomJS 获取文本

使用 Selenium Webdriver 如何检索日期文本

使用 selenium 从标签中提取名称或 href 无需点击

Selenium WebDriver -- 获取 <span> 文本

如何使用python单击使用<span>标签为Selenium webdriver创建的按钮?

如何使用 Selenium WebDriver 和 Java 提取外跨度的文本

无法使用 selenium webdriver python 中的发送键输入文本

如何使用 selenium webdriver 获取 span 标签内的文本?

无法使用 Selenium webdriver 从表中提取 URL 名称