硒中除元素外如何获得元素

2024-04-19 18:24:50 发布

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

我是新来的。你知道吗

有没有可能得到硒中总是存在于另一种元素旁边的元素?你知道吗

假设我想要.title.may-blank关闭https://www.reddit.com/并且总是在选票计数div.midcol.unvoted > div.score.unvoted旁边

theimage

我试着:

//*[contains(@class, "title may-blank ")]/following-sibling::div[@class='midcol unvoted']//*[contains(@class, 'unvoted')]

未检测到xpath


Tags: httpsdivcom元素titlewwwmayclass
1条回答
网友
1楼 · 发布于 2024-04-19 18:24:50

通过下面的CSSXPATH确定第一个Upvote Count

  • CSS

    div#thing_t3_7m64jy > div.midcol.unvoted > div.score.unvoted
    
  • XPATH

    //div[@id='thing_t3_7m64jy']//div[@class='midcol unvoted']//div[@class='score unvoted']
    

通过以下XPATH确定第一个News Item相对于Upvote Count

  • XPATH

    //div[@id='thing_t3_7m64jy']//div[@class='midcol unvoted']//div[@class='score unvoted']//following::a[2]
    

相关问题 更多 >