Creating Functions for Webscraping

GeorgeUl

New Member
Joined
Jan 15, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
  2. Web
First, I have write a FUNCTION(a) with only one mission , open specific webpage, it's worked! This FUNCTION(a) was add into a SUB. Here alright too. I have write a FUNCTION(b) for grab information from specific webpage, nonetheless the FUNCTION(b) shows ERROR as if the webpage not exist, even though open for FUNCTION(a). What I have include to FUNCTION(b) be linked at webpage??

VBA Code:
"FUNCTION(a)"
Function acessarweb(nomesite As String, Optional varie As String = "ie", _
    Optional visivel As Boolean = True)


Set ie = CreateObject("internetexplorer.application")
ie.navigate nomesite
If visivel = True Then
    ie.Visible = True
Else
    ie.Visible = False
End If

Do While ie.busy And ie.readystate <> "READYSTATE_COMPLETE"
DoEvents
Loop

End Function

'-------------------------------------------------------------------------
"FUNCTION(b)"

Function raspar(tagp As String)

Dim tagprincipal As Object
Set ie = CreateObject("internetexplorer.application")
Set tagprincipal = ie.document.getelementsbytagname(tagp) <<< ERROR this line "iwebbrowser2" fail

...
do stuff
loop
for each
etc
...



End Function
'-------------------------------------------

Sub click()

acessarweb "https://br.investing.com/economic-calendar/", True
Function raspar ....



End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You need to open a web page before getting document elements
 
Upvote 0
You need to open a web page before getting document elements
The web page was open through FUNCION(a)... Thus a FUNCTION(b), unexpected, don't have connection with page open before.
I would like have functions for each process. This way would be more simple adjust on future.
 
Upvote 0
is this smart ? Internet Explorer is outdated.
 
Upvote 0
is this smart ? Internet Explorer is outdated.
it's true. I agree with you. when I say "future", I mean next demand, not a future so long. Some users not yet knows others programations languages. The VBA works for them.
 
Upvote 0
Set the IE object variable to be 'global' at the top of the module and within your function B check if this IE variable is not Nothing …​
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top