plinius
plinius

Reputation: 31

scraping web vba oncick

in the link https://www.forebet.com/en/predictions-tips-atl%C3%A9tico-madrid-real-madrid-553878 I want to load the document that is on the page that you click on "uo_t_butt"

I create the script with

Sub provaonclick()

Dim objIE As Object
Dim ele As Object
Dim ele1 As Object


Set objIE = CreateObject("internetexplorer.application")
objIE.Visible = True
objIE.navigate "https://www.forebet.com/it/pronostico-per-real-madrid-liverpool-fc-731893"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
Set ele = objIE.document.getElementsByClassName("tabs-ul")(0)
Set ele1 = ele.document.getElementById("uo_t_butt").Click

End Sub

but in the object ele1 there is nothing

Upvotes: 1

Views: 132

Answers (3)

plinius
plinius

Reputation: 31

Sub provaonclick()
Dim objIE As Object
Dim ele As Object

Set objIE = CreateObject("internetexplorer.application")
objIE.Visible = True
objIE.navigate "https://www.forebet.com/it/pronostico-per-real-madrid-liverpool-fc-731893"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
objIE.document.getElementById("uo_t_butt").Click

Set ele = objIE.document.getElementsByClassName("schema")(1)
Stop
End Sub

sorry all I thought I had solved but my macro just click on "onclick" but does not load the new page in "ele". In "ele" I find the first page that opens not the clicked one

Upvotes: 0

QHarr
QHarr

Reputation: 84475

You can't normally set an element and try to do a click on it at the same time. The Set keyword is for assigning a reference. It is necessary to distinguish between assignment of an object and assignment of the default property of the object. It is this reference type you will be passing around.

This:

Set ele1 = ele.document.getElementById("uo_t_butt").Click

Normally, this would have thrown an error. Weirdly there is a javascript item generated which is JScriptTypeInfo. This , according to this, likely

hides a number of objects that can be found in JScript.dll.

Remove the action (.Click) from the end to set an object in the normal way and you don't need the preliminary object. Work direct of document with the id.

I had no problem using id with:

objIE.document.querySelector("#uo_t_butt").Click

You can use an attribute = value CSS selector

objIE.document.querySelector("[onclick*='uo']").Click

This switches to the unders/overs tab.

enter image description here

Could also use:

objIE.document.querySelector("[id='uo_t_butt']").Click

Upvotes: 0

Mr ML
Mr ML

Reputation: 428

What i think is your problem is that it is a javascript controlling the button.

HTML and javascript isn't my strong suit but the following code works for me:

Sub provaonclick()
Dim objIE As Object

Set objIE = New InternetExplorerMedium
objIE.Visible = True
objIE.navigate "https://www.forebet.com/it/pronostico-per-real-madrid-liverpool-fc-731893"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

With objIE.Document.getElementById("uo_t_butt")
    .Focus
    .Click
End With

End Sub

".Focus" made the code work for me. I don't know what it does though.

EDIT: Actually not using set in front of "objIE.Document.getElementById("uo_t_butt").click" was the difference.

Upvotes: 1

Related Questions