Copilot for Microsoft 365 Tech Accelerator
Feb 28 2024 07:00 AM - Feb 29 2024 10:30 AM (PST)
Microsoft Tech Community

web scraping help

Copper Contributor

i have an old macro that i use alot to pull information off of multiple sites. it was originally setup to use IE but now that site no longer loads correctly in IE. im not really sure how to go about moving it to another browser due to what i have been reading about other browsers not supporting the DOM. im pretty new to writing macros and the original maker is long gone. this is a part of the code

'Gets the info from AM Console
Function ImportAmConsoleData(url) As String()

'Open and hide Internet Explorer
Dim appIE As InternetExplorerMedium
Dim objElement As HTMLDocument
Set appIE = New InternetExplorerMedium
With appIE
.Navigate url
.Visible = True
End With

'If there was an error, the website was not done loading. return here on error and try again
On Error Resume Next

Set objElement = appIE.Document
Dim bodyText As String
bodyText = objElement.body.innerText

'Give AM console a bit of time before checking again
Sleep 50

'check to see if document as loaded completly with all required info.
'cannot check ready state, I believe this is because AM Console was written with Angular and will
'set the ready state to complete even though it is still waiting for info from the server.
hasName = InStr(bodyText, FIRST_NAME_SEARH) > 0
hasID = InStr(bodyText, ID_SEARCH) > 0
hasPhone = InStr(bodyText, PHONE_SEARCH) > 0
hasEmail = InStr(bodyText, EMAIL_SEARCH) > 0
hasDTAndBGC = InStr(bodyText, DRUG_TEST_SEARCH) > 0 And InStr(bodyText, BGC_COMPLETE_SEARCH) > 0
hasEverything = hasName And hasID And hasPhone And hasEmail And hasDTAndBGC

'add a dot to the elipsis to show the program is running

On Error GoTo 0
Loop Until hasEverything

'reset and close IE
Set appIE = Nothing

Dim dataArray(0 To 6) As String
dataArray(0) = findInfo(bodyText, FIRST_NAME_SEARH)
dataArray(1) = findInfo(bodyText, LAST_NAME_SEARCH)
dataArray(2) = findInfo(bodyText, ID_SEARCH)
dataArray(4) = findInfo(bodyText, PHONE_SEARCH)
dataArray(5) = findInfo(bodyText, EMAIL_SEARCH)

'start looking where onboarding tasks are located as to not pull from the dictionary
OnboardingStart = InStr(bodyText, ONBOARDING_SEARCH)
dataArray(6) = findInfo(bodyText, BGC_COMPLETE_SEARCH, OnboardingStart, 2) & "/" & findInfo(bodyText, DRUG_TEST_SEARCH, OnboardingStart, 2)

ImportAmConsoleData = dataArray

End Function

1 Reply
I gurss python selenium suitable to Chrome webkit.
Xmlhttp send request directly.