通过选中网页上的框来获取数据 [英] Getting data by checking the boxes on the web page
问题描述
我想从网站上获取特定日期范围内的数据.该站点地址为" http://arsiv.mackolik.com/Canli-Sonuclar ".此地址中的某些框应选中或不选中.从这些框中选择"Futbol(足球文本)","Basketbol(篮球文本)".将选择"TariheGöre(aOrderBydate)".但是不会标记"Duello(chkDuel)","Iddaa(chkIddaa)",Canlı(chkLive)"和Seçili(chkSelected)".根据这些首选项,我希望将列表表"表中的所有数据与链接地址一起传递.例如,我将一次性获取一个月的数据并将其传输到excel工作表中.我尚未编写代码或更改代码.
I would like to get data for certain date ranges from a website. The site address is "http://arsiv.mackolik.com/Canli-Sonuclar". There are boxes in this address that should be selected or not selected. "Futbol (futbol-text)", "Basketbol (basketbol-text)" will be selected from these boxes. "Tarihe Göre (aOrderBydate)" will be selected. But "Duello (chkDuel)", "Iddaa (chkIddaa)", "Canlı (chkLive)" and "Seçili (chkSelected)" will not be marked. In line with these preferences, I would like to pass all the data in the "list-table" table together with the link addresses. For example, I'll take a month's data in one go and transfer it to the excel sheet. I haven't written a code about it or changed a code.
推荐答案
以下内容将进行选择;有javascript允许等待元素可点击;进行您指定的取消选择;并向您展示如何以一天的增量将日期改回.
The following will make selections; has javascript to allow for wait for element to be clickable; makes the de-selections you specify; and shows you how to change the date back in one day increments.
Option Explicit
Public Sub MakeSelections()
Dim d As WebDriver, t As Date, ws As Worksheet, i As Long, table As Object
Set ws = ThisWorkbook.Worksheets("Sheet1")
Const MAX_WAIT_SEC As Long = 10
Const URL = "http://arsiv.mackolik.com/Canli-Sonuclar#"
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
Set d = New ChromeDriver
With d
.Start "Chrome"
.get URL
.Window.Maximize
With .FindElementByCss("[data-cc-event='click:dismiss']")
.ExecuteAsyncScript(JS_WAIT_CLICKABLE, 3000) _
.Click
End With
.FindElementByCss("#chkSport1").ScrollIntoView
With .FindElementByCss("#chkSport1")
If Not InStr(.Attribute("class"), "selected") > 0 Then
.Click
End If
End With
With .FindElementByCss("#chkSport2")
If Not InStr(.Attribute("class"), "selected") > 0 Then
.Click
End If
End With
With .FindElementByCss("#aOrderByDate")
.ExecuteAsyncScript(JS_WAIT_CLICKABLE, 3000) _
.Click
End With
With .FindElementByCss("#chkDuel")
If InStr(.Attribute("class"), "selected") > 0 Then
.Click
End If
End With
With .FindElementByCss("#chkIddaa")
If InStr(.Attribute("class"), "selected") > 0 Then
.Click
End If
End With
With .FindElementByCss("#chkLive")
If InStr(.Attribute("class"), "selected") > 0 Then
.Click
End If
End With
With .FindElementByCss("#chkSelected")
If InStr(.Attribute("class"), "selected") > 0 Then
.Click
End If
End With
Set clipboard = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
'go back a day at a time.Add a loop here to change multiple days.
For i = 1 To 2
If i > 1 Then
.FindElementByCss("[onclick='gotoDate(-1);']").Click
End If
t = Timer
Do
DoEvents
On Error Resume Next
Set table = .FindElementByCss(".list-table")
If Timer - t > MAX_WAIT_SEC Then Exit Do
On Error GoTo 0
Loop While table Is Nothing
'other code
Next
Stop '<== Delete me later
.Quit
End With
End Sub
这篇关于通过选中网页上的框来获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!