无法使用Selenium和Python从SPAN获得文字
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论