python - 无法使用 selenium webdriver 提取跨度标记中的文本名称
问题描述
我有一张如下表:
我正在尝试使用下面的 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')
推荐阅读
- php - laravel 5.8:未找到 slug 404
- android - 深色模式下的 Android 10 通知图像看起来像一张负面图像
- c# - 使用 EWS 托管 API 和 C# 从邮箱中搜索附件
- rabbitmq - 使用rabbitMq服务器基于IP地址的用户限制
- javascript - 我有 2 个 UI 选项卡。我需要在单击该选项卡外的按钮时激活一个特定选项卡
- ios - Wkwebview 无法在具有库目录路径的 html 中显示图像
- reactjs - 如何在 React js 中读取 xml 文件(data.xml)?
- php - laravel 5:HTML标签在刀片文件中不起作用
- java - MapView:二进制 XML 文件第 13 行:二进制 XML 文件第 13 行:膨胀类错误
- python - 在 python 中部署 azure 函数不会从 requirements.txt 安装依赖项