weixin_54606311
weixin_54606311
2021-01-16 22:42

运用python+selenium自动化时,目的想提出一组元素内的文本,由于页面刷新产生的报错

  • python
  • selenium
#错误代码如下
#<span style="font-family:-apple-system,"SF UI Text",Arial,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif,SimHei,SimSun">报错selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference
#且提取的元素结构全是<span>1.211</span>
#我就是想提出span内的数据然后加以判断</span>elements1 = wd.find_elements_by_css_selector('[class="odds "]>span')
elements2 = wd.find_elements_by_css_selector('[class="odds down blinking"]>span')
elements3 = wd.find_elements_by_css_selector('[class="odds up blinking"]>span')
elements = elements1 + elements2 + elements3
for element in elements:
    print(element.text)
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答