首页 > 解决方案 > 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&nbsp;
        </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&nbsp;
        </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&nbsp;
        </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>

对不起,我糟糕的英语给你带来了困惑。

标签: python-3.xseleniumselenium-webdriver

解决方案


推荐阅读