如何解决如何使用来自 VBA Excel 的输入自动填充网站搜索框?从 chrome 网站提取股票数据到 excel
我刚刚开始学习使用 VBA 自动输入数据,感谢您的帮助! 最后,我想将特定的股票数据从 yahoo Finance 或 finviz 网站提取到 excel 中。
我正在考虑以下步骤,但不确定如何将其转换为 Excel VBA:
- 在搜索框中输入股票代码,但它一直给我一条错误消息“不支持属性”。任何解决此错误消息的建议都会很棒!
Dim obj As New WebDriver
obj.Start "chrome",""
obj.Get "https://finviz.com/screener.ashx"
'following is the element name for that searchbox which I am attempting to fill out the ticker symbol aapl
'<input placeholder="Search ticker,company or profile" type="text" class="" value="">
obj.FindElementById("search").SendKeys ("aapl")
End Sub
-
如果可行,我会在输入股票代码后找出点击搜索/放大镜符号的代码
-
然后将特定的 Xpath 复制到 excel 这似乎有效:
' Get last row in column A
lastrow = Cells(Rows.Count,1).End(xlUp).Row
For r = 2 To lastrow
'Store finvizsaleqoverq in variable (same position for all stocks)
finvizsaleqoverq = bot.FindElementByXPath("/html/body/div[4]/div/table[2]/tbody/tr[9]/td[6]/b").Text
'Write value to worksheet
Sheets(1).Range("J" & r).Value = finvizsaleqoverq
Next r
'for loop finviz ends here
- 然后再次循环回到步骤 1 以输入下一个股票代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。