python-3.x - Selenium 找不到第九个元素 - python
问题描述
我对 Selenium 网络驱动程序有疑问。
我想登录一个网站并从那里收集一些文章。我可以使用我的代码登录网站,但找不到所有元素。
此代码可以找到除“major”和“notice”的第九个元素之外的所有元素。(我不知道为什么,但它可以找到“上传”的第九个元素)
from selenium import webdriver
import MyCode
Data = []
....
driver = webdriver.Chrome()
driver.get(MyCode.url[0])
driver.implicitly_wait(10)
major = driver.find_elements_by_class_name('board-lecture-title')
notice = driver.find_elements_by_xpath('//*[@class=\'post-title\']/*')
upload = driver.find_elements_by_class_name('post-date')
....
driver.close()
这是网站 HTML 代码的一部分
<li class="isnotice" style="width:calc(100% - 20px) !important;">
<span class="post-title">
<a href="https://url">
<span class="board-lecture-title">[Course]</span>Title
</a>
</span>
<br>
<span class="post-date">2020년 7월 30일, 목요일, 오전 10:58</span>
<span class="post-viewinfo area-right">
0
<br>
<span>View</span>
</span>
</li>
<li class="isnotice" style="width:calc(100% - 20px) !important;">
<span class="post-title">
<a href="https://url">
<span class="board-lecture-title">[Course]</span>Title
</a>
</span>
<br>
<span class="post-date">2020년 7월 15일, 수요일, 오후 12:20</span>
<span class="post-viewinfo area-right">
0
<br>
<span>View</span>
</span>
</li>
<li class="isnotice" style="width:calc(100% - 20px) !important;">
<span class="post-title">
<a href="https://url">
<span class="board-lecture-title">[Course]</span>Title
</a>
</span>
<br>
<span class="post-date">2020년 6월 29일, 월요일, 오전 11:18</span>
<span class="post-viewinfo area-right">
47
<br>
<span>View</span>
</span>
....
</ul>
对不起,我糟糕的英语给你带来了困惑。
解决方案
推荐阅读
- scala - 将 Mozilla Rhino 与 SBT 一起使用 - 未知工件
- python - 如何让我的 python 程序运行得更快?
- python - 我对 Keras 模型的输入形状有疑问
- python - 当我尝试使用 setter 时出现错误。错误消息是 AttributeError: 'function' object has no attribute 'setter'
- mysql - 更新节点 js mysql2 中的几个值
- c# - 为什么我的 C# 对象不能在 windows 窗体图形中移动?
- node.js - 使用内部 id 更新 mongo 模型的内部对象
- android - @UiThreadTest 注释在片段的写测试中不起作用
- ruby-on-rails - Devise-OmniAuth Facebook 登录卡在 CORS 问题上
- python - Python用空格替换字符串