-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSelenium_ariva.bas
More file actions
129 lines (101 loc) · 3.73 KB
/
Copy pathSelenium_ariva.bas
File metadata and controls
129 lines (101 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Attribute VB_Name = "Selenium_ariva"
' you are free to use/modify/sell this table as you wish
Option Explicit
Const consentUUID = "985a0cc2-9534-4bbc-97a3-e265d6ec630d_2"
Private SeleniumDriver_ariva As Variant
Private seleniumStarted As Boolean
Dim keys As New Selenium.keys
Public cookiesAccepted As Boolean
Function GetAriva_Fund(url$, wkn$)
Dim tmpWebElements As WebElements
Dim tmpWebElement As WebElement
Dim tmpString As String
Dim tmpStrings() As String
Dim i%
If IsEmpty(SeleniumDriver_ariva) Then
' create new selenium driver
Set SeleniumDriver_ariva = CreateObject2("Selenium.ChromeDriver")
SeleniumDriver_ariva.SetPreference "download.default_directory", Environ$("USERPROFILE") & "\Downloads\"
seleniumStarted = True
End If
' if "url" is empty, then search for fund according to WKN and update url
Call SeleniumDriver_ariva.Get(url)
Call Sleep(3000)
AcceptCookies
' //div[@id='pageHistoricQuotes']/div[6]/div[4]/form/ul/li[4]/input
Set tmpWebElements = _
SeleniumDriver_ariva.FindElementsByXPath("//div[@id='pageHistoricQuotes']/div[6]/div[4]/form/ul/li[4]/input")
Call tmpWebElements(1).SendKeys(" ")
' tmpWebElements(1).Click
End Function
Sub CloseSeleniumDriver()
If Not IsEmpty(SeleniumDriver_ariva) Then
SeleniumDriver_ariva.Close
SeleniumDriver_ariva.Quit
End If
End Sub
Sub AcceptCookies()
Dim tmpWebElement As WebElement
Dim cookies
If Not cookiesAccepted Then
Call SeleniumDriver_ariva.Manage.AddCookie("consentUUID", _
consentUUID, ".ariva.de")
Call SeleniumDriver_ariva.Get(SeleniumDriver_ariva.url)
cookiesAccepted = True
End If
End Sub
Function CreateObject2(typeName As String) As Object
Static domain As mscorlib.AppDomain
If domain Is Nothing Then
Dim host As New mscoree.CorRuntimeHost
host.Start
host.GetDefaultDomain domain
End If
Set CreateObject2 = domain.CreateInstanceFrom(Environ("USERPROFILE") & "\AppData\Local\SeleniumBasic\Selenium.dll", typeName).Unwrap
End Function
Sub DeleteFile(ByVal FileToDelete As String)
If Dir(FileToDelete) <> "" Then
' First remove readonly attribute, if set
SetAttr FileToDelete, vbNormal
' Then delete the file
Kill FileToDelete
End If
End Sub
' In time series only close price is used.
Sub ReadFundsTimeSeries(outDates_reference() As Date, outTimeSeries#(), ticker$)
Dim fileName As String
Dim i%, j%
Dim line As String
Dim arrayOfLines() As String
Dim arrayOfElements() As String
Dim tmpDate As Date
Dim decimalSeparator$
ReDim outTimeSeries(UBound(outDates_reference))
fileName = Environ$("USERPROFILE") & "\Downloads\wkn_" + ticker + "_historic.csv"
Call Sleep(2000)
' open CSV
Open fileName For Input As #1 ' Open file for input
Line Input #1, line
arrayOfLines = Split(line, vbLf)
Close #1 ' Close file.
decimalSeparator = Application.decimalSeparator
For i = 1 To UBound(arrayOfLines)
arrayOfElements = Split(arrayOfLines(i), ";")
If arrayOfLines(i) = "" Then
Exit Sub
End If
tmpDate = CDate(arrayOfElements(0))
' search for
For j = 1 To UBound(outDates_reference)
' look for the same dates:
If tmpDate = outDates_reference(j) Then
If arrayOfElements(4) = "" Then
outTimeSeries(j) = Undefined
Else
outTimeSeries(j) = CDbl(arrayOfElements(4))
End If
Exit For
End If
Next j
Next i
End Sub