“错误438对象不支持”和VBA-Selenium

时间:2019-06-04 12:40:11

标签: vba selenium

我是新手,请尝试完成我的作业。我正在尝试通过在此网站上使用VBA-Selenium从className获取符号,公司名称,股价

https://www.barchart.com/stocks/indices/russell/russell2000?page=20&orderBy=lastPrice&orderDir=asc&viewName=main

但是我仍然遇到错误

代码行mysheet.Cells(i,1).Value = mytables.FindElementByClass(“ symbol text-left”)。Text中的“运行时错误'438'对象不支持此属性或方法”。我应该如何解决这个问题?我已经尝试安装新的Selenium补丁,但无法正常工作。

还有另一个问题,该页面有20页,我必须单击每一页才能得出股票价格。我怎样才能做到这一点?请帮助这个可怜的学生。

Public Sub Russelcrawler()
Dim driver As New WebDriver
Dim mytables As WebElements, table As WebElement, i As Integer, mysheet As Worksheet

With driver
    .Start "IE", "https://www.barchart.com/stocks/indices/russell/russell2000?page=20&orderBy=lastPrice&orderDir=asc&viewName=main"
    .Get "/"
End With


Set mysheet = Sheets("Russel")

Set mytables = driver.FindElementsByClass("bc-datatable")

i = 2
For Each table In mytables

mysheet.Cells(i, 1).Value = mytables.FindElementByClass("symbol text-left").Text
mysheet.Cells(i, 2).Value = mytables.FindElementByClass("symbolName text-left").Text
mysheet.Cells(i, 3).Value = mytables.FindElementByClass("lastPrice").Text

i = i + 1

Next

End Sub

0 个答案:

没有答案