【发布时间】:2018-10-08 06:58:31
【问题描述】:
我想使用 selenium VBA 从Yahoo Finance KOSPI COmposite Index 下载一些数据。
我在单击日期选择器箭头以使迷你窗口选择结束日期为今天时遇到了困难。我尝试在chrome中通过selenium IDE记录marco,但是当我单击时间段的箭头以使日期选择器可见时,IDE没有记录步骤。
下面是我在 VBA 中的代码。
Public Function seleniumKorea(bot As WebDriver)
Dim url As String
url = "https://finance.yahoo.com/quote/%5EKS11/history?period1=1484018309&period2=1515554309&interval=1d&filter=history&frequency=1d"
bot.Start "chrome", url
bot.Get "/"
'Not sure how to add date picker here
bot.FindElementByName("endDate").Clear
bot.FindElementByName("endDate").SendKeys (Date)
bot.FindElementByXPath("(.//*[normalize-space(text()) and normalize-space(.)='End Date'])[1]/following::button[1]").Click
Application.Wait (Now + TimeValue("0:01:00"))
bot.FindElementByXPath("(.//*[normalize-space(text()) and normalize-space(.)='As of'])[1]/following::div[4]").Click
Application.Wait (Now + TimeValue("0:01:00"))
bot.FindElementByXPath("(.//*[normalize-space(text()) and normalize-space(.)='Currency in KRW'])[1]/following::span[2]").Click
Application.Wait (Now + TimeValue("0:01:00"))
End Function
我尝试使用 ByXPath 获取 svg 类但失败了。
提前致谢。
【问题讨论】:
标签: vba selenium selenium-webdriver web-scraping