通过xpath获取循环中的所有元素

2024-09-30 02:29:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在学习python

html是:

<ol class="item-section">
<li>
   <div class="abc xyz">
           <div class="foo qwe">
                 <a href="/watch123"></a>
           </div>
   </div>           
</li>
<li>
     <div class="abc xyz">
           <div class="foo qwe">
                 <a href="/watch456"></a>
           </div>
   </div>
</li>
<li>
     <div class="abc xyz">
           <div class="foo qwe">
                 <a href="/watch678"></a>
           </div>
   </div>
</li>
</ol>

我想通过xpath从列表中获取所有href 我试过了

^{pr2}$

但是它给出了错误Can't convert 'int' object to str implicitly 如果我只是用

link = item.find_element_by_xpath("//div[@class='foo qwe']/a")

我多次得到第一个href


Tags: divfoohtmlsectionliitemxpathclass

热门问题