我想使用Selenium和Python在网页中找到一个元素,如何获得输入值?

发布于 2025-02-05 15:40:44 字数 627 浏览 2 评论 0原文

因此,这是我正在与之合作的网站的细分市场。特别是我想从中获得价值。我可以使用best_offer = driver.find_element_by_class_name('showbestoffer')在硒中访问跨度类,我可以在标签内获取值吗?

<div class="ebayBestOfferAccepted" id="363858864519-bestOffer-simple"><div class="bestOfferSoldPrice" style="display: flex; align-items: center; justify-content: center;"><span class="bestOfferData"><b>Best Offer Accepted Price:&nbsp;&nbsp;</b></span><span class="bestOfferLink"><span class="showBestOffer"><input type="submit" value="15.00 USD"></span></span></div></div>

So here's the segment of the website that I'm working with. Specifically I wanna obtain the value from . I can access the span class using best_offer = driver.find_element_by_class_name('showBestOffer') in Selenium, is there a way I can fetch the value inside the tag?

<div class="ebayBestOfferAccepted" id="363858864519-bestOffer-simple"><div class="bestOfferSoldPrice" style="display: flex; align-items: center; justify-content: center;"><span class="bestOfferData"><b>Best Offer Accepted Price:  </b></span><span class="bestOfferLink"><span class="showBestOffer"><input type="submit" value="15.00 USD"></span></span></div></div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

还给你自由 2025-02-12 15:40:44
best_offer = driver.find_element_by_class_name('showBestOffer').get_text()
best_offer = driver.find_element_by_class_name('showBestOffer').get_text()
别念他 2025-02-12 15:40:44

您可以尝试此解决方案

span = driver.find_element(By.CSS_SELECTOR,"span[class='showBestOffer']")
input = span.find_element(By.TAG_NAME, "input")
bestOffer = input.get_attribute("value")

You can try this solution

span = driver.find_element(By.CSS_SELECTOR,"span[class='showBestOffer']")
input = span.find_element(By.TAG_NAME, "input")
bestOffer = input.get_attribute("value")
动听の歌 2025-02-12 15:40:44

使用XPath

input = driver.findElement(By.xpath('//span[@class="showBestOffer"]/input'))
val = input.get_attribute("value")

Using xpath

input = driver.findElement(By.xpath('//span[@class="showBestOffer"]/input'))
val = input.get_attribute("value")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文