在python中搜索特定html元素后获取空列表

在python中搜索特定html元素后获取空列表,python,list,Python,List,给定下一个代码,我将尝试使用作为基础id=“rrtable”来达到最后一个“tr” 实际上,上面返回的是一个空列表。 我遗漏了什么?请注意,Xpath的行为与JSON不同,因为Xpath将返回定位器指定的元素,而不是元素加上对象中包含的所有元素。表元素本身是空的。表格单元格包含您希望最终访问的数据。如果它没有抛出ElementNotFound错误,那么它确实找到了表 首先尝试获取最小可行的数据元素以检查代码,然后分支并编写递归元素以读取整个表。1)您使用的是什么库,2)这不是有效的HTML?你能

给定下一个代码,我将尝试使用作为基础id=“rrtable”来达到最后一个“tr”

实际上,上面返回的是一个空列表。
我遗漏了什么?

请注意,Xpath的行为与JSON不同,因为Xpath将返回定位器指定的元素,而不是元素加上对象中包含的所有元素。表元素本身是空的。表格单元格包含您希望最终访问的数据。如果它没有抛出ElementNotFound错误,那么它确实找到了表


首先尝试获取最小可行的数据元素以检查代码,然后分支并编写递归元素以读取整个表。

1)您使用的是什么库,2)这不是有效的HTML?你能举一个可重复性最低的例子吗?谢谢你,BCR。最后我成功地得到了我想要的
<div id="rrtable">
    <table class="genTbl reportTbl">
    <tbody><tr class="alignBottom" id="header_row">
              <th><span class="lightgrayFont arial_11 noBold">Period Ending:</span></th>
                 <th><span class="bold">2020</span><div class="noBold arial_11">31/08</div></th>
                 <th><span class="bold">2020</span><div class="noBold arial_11">31/05</div></th>
                 <th><span class="bold">2020</span><div class="noBold arial_11">29/02</div></th>
                 <th><span class="bold">2019</span><div class="noBold arial_11">30/11</div></th>

             </tr>
        <tr class="secondRow" id="cas_added_row">
        <th><span class="arial_11 noBold lightgrayFont">Period Length:</span></th>
        <th><span class="noBold lightgrayFont">12 Months</span></th>
        <th><span class="noBold lightgrayFont">9 Months</span></th>
        <th><span class="noBold lightgrayFont">6 Months</span></th>
        <th><span class="noBold lightgrayFont">3 Months</span></th>
    </tr>
            
    </tbody><tbody>
        <tr> 
        ...
        </tr>
print(root.xpath("//div[@id='rrtable']"))