[英]How to get the xpath of elements inside a div using python selenium
<div class="col-md-6 profile-card_col">
<span class="label">نام شرکت :</span>
<p class="value">اسپاد فولاد آسیا</p>
</div>
Its been a while I have been trying to fix this problem but what appears to people think I'm looking for is to get the value in the <span>
and <p>
but I'm trying to get the xpath of both using python selenium the challenge is that I do not know anything about the <span>
and <p>
and the code above is just a example.有一段时间我一直在尝试解决这个问题,但人们认为我正在寻找的是获取
<span>
和<p>
中的值,但我正在尝试使用 python 获取两者的 xpath selenium 的挑战是我对<span>
和<p>
一无所知,上面的代码只是一个例子。 So my main goal to get the xpath of both the <span>
and <p>
only using the the main div
xpath .所以我的主要目标是仅使用主
div
xpath获取<span>
和<p>
的 xpath 。
in chrome: You can open the chrome developer console and right click on the tag you want and then copy the sub menu and then click on an option called Xpath.在 chrome 中:您可以打开 chrome 开发人员控制台并右键单击所需的标签,然后复制子菜单,然后单击名为 Xpath 的选项。 Xpath will copy the tag you want for you.
Xpath 会为你复制你想要的标签。
You can try the below XPath:您可以尝试以下 XPath:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
span_value = driver.find_element(By.XPATH, ".//*[@class='col-md-6 profile-card_col']/span").text
paragraph_value = driver.find_element(By.XPATH, ".//*[@class='col-md-6 profile-card_col']/p").text
Next time, post the URL and the full code you've tried and explain your issue clearly and briefly.下次,发布 URL 和您尝试过的完整代码,并清楚、简要地解释您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.