我想编写一个vba程序,该程序可以从网页自动下载历史库存数据。选择数据并单击下载按钮已在起作用。但是我也想更改日期,不适用于我的代码。
我想更改日期的Element的相应HTML代码,您可以在以下链接下找到该日期:
我要更改日期的元素的HTML代码
我现在使用的代码如下:
Public Sub MakeChanges()
'VBE > Tools > References > Selenium Type Library
'Download: https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0
Dim d As WebDriver, t As Date
Set d = New ChromeDriver
Const url = "https://www.dukascopy.com/swiss/english/marketwatch/historical/"
With d
.Start "Chrome"
.get url
.SwitchToFrame .FindElementByCss("script + iframe")
t = Timer
Do
With .FindElementByCss("[data-instrument='EUR/USD']")
.Click
If .Attribute("aria-selected") Then Exit Do
End With
Loop While Timer - t < 10
MsgBox "please login"
'set the date
With .FindElementByCss("a-b-c.a-ab-v-y-x > div")
.FindElementByTag("span").innerText = "2017-01-01"
End With
'end set date
With .FindElementByCss(".d-wh-vg-v-p > div")
If Not .Attribute("aria-disabled") Then .Click
End With
Stop
.Quit
End With
End Sub
我非常感谢您的帮助!
请尝试以下方法。实际上,它单击年份和月份的下拉菜单,然后通过itemindex
属性值选择适当的项目。
在年份的情况下,取决于当前显示的内容,期望的年份可能不在下拉列表中。该代码使用固定次数的<>按钮单击来确定是否可以找到所需的年份。可以在代码顶部将此数字设置为常量,并在需要时在此更改。
要选择日期,将循环收集天数,如果找到了所需的天数,则将其选中。
Javascript用于等待某些元素变为可单击状态,以及用于出现下拉菜单的定时循环。这会根据事件何时可操作来计时,以产生所需的结果。
Option Explicit
Public Sub MakeChanges()
'VBE > Tools > References > Selenium Type Library
'Download: https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0
Const url = "https://www.dukascopy.com/swiss/english/marketwatch/historical/"
Const MAX_WAIT_SEC As Long = 10
Const JS_WAIT_CLICKABLE = _
"var target = this, endtime = Date.now() + arguments[0];" & _
"(function check_clickable() {" & _
" var r = target.getBoundingClientRect(), x = r.left+r.width/2, y = r.top+r.height/2;" & _
" for (var e = document.elementFromPoint(x , y); e; e = e.parentElement)" & _
" if (e === target){ callback(target); return; }" & _
" if (Date.now() > endtime) { callback(target); return; }" & _
" setTimeout(check_clickable, 60);" & _
"})();" 'by @florentbr
Dim d As WebDriver, t As Date
Dim myYear As String, myMonth As String, myDay As String
Set d = New ChromeDriver
myYear = "2017"
myMonth = "January"
myDay = "1"
With d
.start "Chrome"
.get url
.SwitchToFrame .FindElementByCss("script + iframe") '<==switch to frame
'You should add tests for acceptable values e.g. January-December for MonthName, day as appropriate for month
Dim monthIndex As Long, yearIndex As Long, item As Object, dropDown As Object
monthIndex = Month(DateValue("01 " & myMonth & " 2019")) - 1 '<== get month number from name and -1 to get value to use in attribute selector
t = Timer
Do '<== timed loop for month dropdown to be present
On Error Resume Next
Set dropDown = .FindElementByCss(".d-wh-vg-xh span span")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While dropDown Is Nothing
If dropDown Is Nothing Then Exit Sub
With dropDown '<== wait for drop down to be clickable
.ExecuteAsyncScript(JS_WAIT_CLICKABLE, 3000) _
.Click
End With
With .FindElementByCss(".d-Ch-fi-mi")
.ExecuteAsyncScript(JS_WAIT_CLICKABLE, 3000) _
.Click '<== display month dropdown
End With
.FindElementByCss(".d-Ch-fi-u [itemindex='" & monthIndex & "']").Click '<select month by index
Dim yearIndices As Object, i As Long, j As Long, currentYear As String, z As Long, dayFound As Boolean
currentYear = .FindElementByCss(".d-Ch-fi-ni").Text '<= find currently displayed year
Set yearIndices = CreateObject("Scripting.Dictionary")
For i = CLng(currentYear) - 5 To CLng(currentYear) + 5 '<== gather range of year options in dropdown into
'dictionary where key is year and value is the value required to select in attribute selector
yearIndices(CStr(i)) = CStr(j)
j = j + 1
Next
If yearIndices.Exists(myYear) Then '<check dictionary to see if year desired present
yearIndex = yearIndices(myYear)
.FindElementByCss(".d-Ch-fi-ni").Click '<== display year dropdown
.FindElementByCss("div:nth-child(11) [itemindex='" & yearIndex & "']").Click '<==select year
Else '<== year not present so loop clicking either year add or year subtract to see if desired year does become present
Dim adjustButton As Object
Set adjustButton = IIf(CLng(currentYear) > CLng(myYear),.FindElementByCss("d-Ch-fi-previousYear"), .FindElementByCss("d-Ch-fi-nextYear"))
Do
adjustButton.Click
If z > 15 Then Exit Sub
z = z + 1
Loop Until .FindElementByCss(".d-Ch-fi-ni").Text = myYear
End If
Dim daysList As Object
Set daysList = .FindElementsByCss("div:nth-child(11) td") '<==gather all the days
For Each item In daysList '<==loop days in month until required one found
If item.Text = myDay Then
item.Click
Exit For
End If
Next
Stop
.Quit
End With
End Sub
问题内容: 我有一个小问题,我正在开发一个应用程序,我需要将每周的开始日期从星期一更改为另一个(星期四,星期六)。在Android中这可能吗,我需要计算周的开始及其知道日期的结束。(例如,星期几从星期四开始) 注意:我只是android开发的初学者。这是我的代码SimpleDateFormat dateformate = new SimpleDateFormat(“ dd / MM”); 使用上面
我有一个小问题,我正在开发一个应用程序,我需要将一周的开始日从星期一更改为另一个(星期四,星期六)。这在android中可能吗,我需要计算一周的开始和结束知道日期。(例如,一周从星期四开始) 注意:我只是android开发的初学者。这是我的代码SimpleDataFormat DateFormat=new SimpleDataFormat(“dd/MM”); 使用上面的代码,我得到了结果,但星期一
我使用react日历来显示日历。当前,当我尝试从其onChange方法访问日期时。 我想以这样的方式更改此日期格式(07/18/2020)。 我尝试了格式化LongDate按照他们的留档,因为我无法得到想要的结果。
我已经了解到您不能将事件添加到默认的calendarview(它只是在用户的默认日历中处理),所以我使用了caldroid https://github.com/roomorama/caldroid/blob/master/readme.md,到目前为止,它对文档很有帮助,但当涉及到一件事时,我感到迷茫。 我想做的是改变任何日期的颜色,有一个事件。文档中说要制作一个drawable并将其放入单元格
问题内容: 您好我在Java中使用 我想要的是更改“日历”值,并在下一周/上一周进行。 我试过了 但这很奇怪 问题答案: 您是否尝试过(从javadoc复制/粘贴):
问题内容: 现在,我的构建过程使用MS Build从源进行构建,并在构建过程中执行自定义程序。我在程序中写入控制台的所有内容都记录在控制台输出中。 但是,我也想在用户界面的“更改”和/或“状态”部分中记录一些条目(类似于SVN所做的事情)。 如何才能做到这一点? 问题答案: // This is a deliciously convoluted and fragile hack to force