简体   繁体   English

如何使用单个XPath匹配多个元素标签

[英]How to match multiple element tags with single XPath

<a data-ft="{&quot;tn&quot;:&quot;T&quot;}" data-hovercard="/ajax/hovercard/hovercard.php?id=1063783263698960&amp;extragetparams=%7B%22on_public_ufi%22%3Atrue%2C%22hc_location%22%3A%22ufi%22%7D" href="https://www.facebook.com/aslanneferler.org/?rc=p" class="img _8o _8s UFIImageBlockImage" tabindex="-1" aria-hidden="true" aria-controls="js_23b" aria-haspopup="true" aria-describedby="js_23c" id="js_23d"><img alt="Aslan Neferler Tim" class="img UFIActorImage _54ru img" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-1/p32x32/16649279_1243625492381402_3963550962824882029_n.jpg?oh=7b12626e660bc99add267af31ed0c47e&amp;oe=59E2A54C"></a>


<img alt="Abdurrezzak Taşkın" class="img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-1/p32x32/18838939_1832790993710312_8699687160338170698_n.jpg?oh=0f627688abff94244dce906bd99dc56b&amp;oe=59A4A24B">

How can I select two of the tags you have seen above? 如何选择您在上面看到的两个标签? I want to select 10 elements in total in one "a tagged", nine "img tagged" in total. 我想在一个“被标记”中总共选择10个元素,总共九个“被标记img”中的元素。

I wrote the following lines of code. 我编写了以下代码行。 But I did not get the result I wanted. 但是我没有得到想要的结果。 What do you recommend. 您有什么推荐的吗。 I want to do this using Selenium in Python. 我想在Python中使用Selenium做到这一点。

driver.find_elements_by_xpath(
                    '//img[@class="img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img"]') or driver.find_elements_by_xpath('//*[@id="js_kq"]')

在xpath下使用相同的名称,并让我知道是否存在任何问题

//a[@id='js_23d'] | //img[@class='img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM