无法使用Selenium和Python从SPAN获得文字

发布于 2025-02-08 05:47:23 字数 1021 浏览 1 评论 0原文

我正在使用Selenium和Python刮擦和控制网站。我能够从网站获得所有其他跨度文本,但无法抓住此特定的文本。我已经搜索了互联网的尽头,试图找到没有运气的解决方案。

这是我要抓取的内容的片段:

    <td style="width:15%;"></td><td colspan="3" style="width:100%;"><span id="WebSplitter1_tmpl1_ContentPlaceHolder1_eMessage" style="color:Red;">The Date Range allowed is '90 Days Before' Today plus Tomorrow, but Tomorrow's data only after 5:00 PM Today.</span></td>
</tr>

这位于同一页面上,就在我试图抓住并按预期工作的元素旁边:

    </tbody></table></td><td style="width:25%;"><span id="WebSplitter1_tmpl1_ContentPlaceHolder1_lCapEffTm" class="bodytext">Eff Time:  09:00 CCT</span></td><td style="width:30%;"></td>
</tr><tr>

我的代码:

elem = browser.find_elements(by.xpath,“ //*) [@ID ='webplitter1_tmpl1_contentplaceholder1_emessage']

) 打印(i.text)

这将正常抓住它上方的跨度(以lcapefftm结尾)并返回,“ eff Time:09:00 CCT”,如所预期。另一个跨度(以Emessage结尾)是唯一在页面上给我问题的跨度。

I'm using selenium and python to scrape and control a website. I am able to get all the other span text from the site but unable to grab this specific one. I've searched to the end of the internet trying to find a solution with no luck.

Here is the snippet of what I am trying to grab:

    <td style="width:15%;"></td><td colspan="3" style="width:100%;"><span id="WebSplitter1_tmpl1_ContentPlaceHolder1_eMessage" style="color:Red;">The Date Range allowed is '90 Days Before' Today plus Tomorrow, but Tomorrow's data only after 5:00 PM Today.</span></td>
</tr>

This is on the same page just next to the element I am trying to grab and works as expected:

    </tbody></table></td><td style="width:25%;"><span id="WebSplitter1_tmpl1_ContentPlaceHolder1_lCapEffTm" class="bodytext">Eff Time:  09:00 CCT</span></td><td style="width:30%;"></td>
</tr><tr>

My code:

elem = browser.find_elements(By.XPATH, "//*[@id='WebSplitter1_tmpl1_ContentPlaceHolder1_eMessage']")

for i in elem:
print(i.text)

This will works fine to grab the span above it (ending in lCapEffTm) and returns, "Eff Time: 09:00 CCT" as expected. The other span (ending in eMessage) is the only one that is giving me issues on the page.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文