宏代码(使用seleniumbasic)基本上是股票数据堆叠程序,它使用以下代码从DSE收集数据:达卡证券交易所
xPathonUrl
excel宏中的函数(),然后在excel表中显示实时数据(实收资本、所有权数据:期间、赞助商/董事(%)、政府(%),研究所(%))、外国(%)和公众(%)。
问题是,它在我的电脑和我的一些朋友的电脑上运行得很好,但在老年人的电脑上却不行,我基本上是为他们构建项目来检索实时股票数据的。
代码为:
Sub PaidupCapital()
Dim autobot As New WebDriver, By As New By
autobot.AddArgument "--headless"
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
autobot.Start "chrome"
autobot.Wait (3300)
For i = 5 To lastrow
autobot.Wait (3300)
link = Sheets(2).Range("a" & i).Value
autobot.ExecuteScript "window.open(arguments[0])", link
autobot.SwitchToNextWindow
autobot.Wait (3300)
If autobot.IsElementPresent(By.XPath("//*[@id='consent-page']/div/div/div/div[2]/div[2]/form/button")) Then
autobot.FindElementByXPath("//*[@id='consent-page']/div/div/div/div[2]/div[2]/form/button").Click
End If
paidcapital = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[4]/table/tbody/tr[2]/td[1]").Text
Sheets(2).Range("I" & i).Value = paidcapital
foreign = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[11]/table/tbody/tr[6]/td[2]/table/tbody/tr/td[4]").Text
Sheets(2).Range("Y" & i).Value = foreign
pub = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[11]/table/tbody/tr[6]/td[2]/table/tbody/tr/td[5]").Text
Sheets(2).Range("Z" & i).Value = pub
institute = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[11]/table/tbody/tr[6]/td[2]/table/tbody/tr/td[3]").Text
Sheets(2).Range("X" & i).Value = institute
govt = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[11]/table/tbody/tr[6]/td[2]/table/tbody/tr/td[2]").Text
Sheets(2).Range("W" & i).Value = govt
director = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[11]/table/tbody/tr[6]/td[2]/table/tbody/tr/td[1]").Text
Sheets(2).Range("V" & i).Value = director
Period = autobot.FindElementByXPath("/html/body/div[2]/section/div/div[3]/div[1]/div/div[11]/table/tbody/tr[6]/td[1]").Text
Sheets(2).Range("U" & i).Value = Period
Next i
MsgBox "Congratulations! Data has beed updated :)"
End Sub