首页 > 解决方案 > 使用 selenium v​​ba 从网站获取文本的问题

问题描述

我正在尝试将一些数据从网站获取到 Excel 中......如果我在 Chrome 中使用 View pagesource 它会显示

  <div class="buttons">
    <div class="vote" onclick="Vote.cast();" data-tooltip-text="Stem op deze foto">
      <div class="container">
        <div class="voteIcon">Stem op deze foto!</div>
        <div class="votes"></div>
      </div>
    </div>
  </div>

当我检查它时,它显示

<div class="buttons">
    <div class="vote voted" onclick="Vote.cast();" data-tooltip-text="Stem op deze foto">
      <div class="container">
        <div class="voteIcon">Stem op deze foto!</div>
        <div class="votes">2</div>
      </div>
    </div>
  </div>
  

数字 2(在本例中)是我要提取的文本……但无论我尝试什么,它都只返回一个空字符串。

ActiveWorkbook.ActiveSheet.Cells(i, 2).Value = detailbot.FindElementByClass("votes").text

在我看来应该可以解决问题,但事实并非如此

标签: htmlexcelvbaseleniumweb-scraping

解决方案


我从未使用过 vba,但我发现了这个问题:https ://github.com/7Gabriel/selenium-vba/issues/126#issuecomment-210692163

似乎detailbot.findElementByClassName("votes").Text应该返回一个值。


推荐阅读