How to switch from IE to XMLHTTP60 - vba

I need to switch from ie to xmhttp60, and get the result of the execScript. Is there any way to do it? Below the code
I'm using.
Sub MostrarMasButton()
Dim ie As InternetExplorer
Dim CurrentWindow As HTMLWindowProxy
url = "https://es.investing.com/equities/amazon-com-inc-earnings"
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate url
Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop
ie.document.parentWindow.execScript ("showMoreEarningsHistory(6435, this)")
End Sub

Related

VBA WebScraping a website that requires sendkeys

I need to webscrape a website that I actually have to type the keys to show the password form.
I've tried this code with no success (even using the right login)
Sub login()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate ("https://wsvr10.coamo.com.br/npl/#!/login")
While IE.readyState <> READYSTATE_COMPLETE
Wend
sng = Timer
Do While sng + 5 > Timer
Loop
Dim idoc As MSHTML.HTMLDocument
Set idoc = IE.document
idoc.all.cpf.Value = "11111111111"

i am writing vba code to scrape data from web, I got error of Remote server Machine does not exist or is unavialable

Sub Launch_website()
Dim ie As SHDocVw.InternetExplorer
Dim myurl As String
Set ie = New SHDocVw.InternetExplorer
ie.Visible = True
myurl = "https://www.lifeinscouncil.org/industry%20information/NewBusinessPerformance"
'ie.Navigate "https://www.lifeinscouncil.org/industry%20information/NewBusinessPerformance" '
ie.Navigate myurl
'On Error Resume Next
Do While ie.ReadyState <> READYSTATE_COMPLETE
Loop

The data in A "id" is not printing

i am trying this
Sub JJ()
Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim ha As String
IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set hdoc = IE.document
ha = hdoc.getElementById("preOpenFp").innerText
Debug.Print ha
End Sub
Please suggest any solution for that.
the point is in image.
If you want to read the data from the Pre-Open Markt you have to change the url as follows https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB#info-preopenmkt.Try this code.
Sub JJ()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
'Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim ha As String
IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB#info-preopenmkt"
Do While IE.Busy: DoEvents: Loop
Do While IE.Busy And Not IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop
'Application.Wait (Now + TimeValue("0:00:15"))
Set hdoc = IE.document
ha = hdoc.getElementById("preOpenIep").innerText
Debug.Print (ha)
End Sub

Get cookie from InternetExplorer object

I'm working a VBA project uses the following code to automate IE. How can I able to get cookies from current IE session?
Sub IE()
Dim objIE As InternetExplorer
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "targeturl"
While objIE.Busy
DoEvents
Wend
getCookie = objIE.Cookie
End Sub
getCookie = objIE.document.Cookie

How to select values from Dropdown menu on a webpage:VBA

My code :
Sub login()
Dim IE As Object
Dim HTMLDoc As Object, HTMLDoc2 As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https:/com/1/19/login.esp"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.Document
With HTMLDoc
HTMLDoc.getElementById("USERNAME").Value = "xxxx" 'Entering credential
HTMLDoc.getElementById("PASSWORD").Value = "yyyyy"
End With
Set objCollection = IE.Document.getElementById("loginbutton")
objCollection.Click
'Second webpage
Do While IE.Busy Or IE.ReadyState <> 4: Loop ' opening the second webpage
Set HTMLDoc2 = IE.Document
With HTMLDoc2
**HTMLDoc2.getElementById("DEPARTMENTID").selectedindex = 1 'Drop down menu
HTMLDoc2.getElementById("DEPARTMENTID").FireEvent ("onchange")**
End With
Set objCollection = IE.Document.getElementById("loginbutton")
objCollection.Click
End Sub
Q)What code changes do I do to select Dwell_DF option Value 1567?
The above code gives run time error '424' : Object required.
HTMLDoc2.getElementById("DEPARTMENTID").selectedindex = 1 'Drop down menu
HTMLDoc2.getElementById("DEPARTMENTID").FireEvent ("onchange")
The above line give the error.
In the first webpage I fill the login credentials then in the next page is that of the image pasted with this post. Here I want to change the value in the drop down menu.
Give this a try. The value "1567" corresponds with the InnerText "Dwell_DF".
With HTMLDoc2
.getElementById("DEPARTMENTID").Focus
.getElementById("DEPARTMENTID").Value = "1567" 'You can also loop to find the text of the Option
.getElementById("DEPARTMENTID").FireEvent ("onchange")
End With
It should be something like this.
Sub passValueToComboBox1()
Dim ie As Object
Dim oHTML_Element As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://your_URL_here.php"
While ie.Busy Or ie.readyState <> 4: DoEvents: Wend
Set oHTML_Element = ie.document.getElementsByName("selectedReportClass")(0)
If Not oHTML_Element Is Nothing Then oHTML_Element.Value = "FUBU7"
For Each oHTML_Element In ie.document.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
End Sub
Check out the link below for some other ideas of how to programatically interact with a web site.
http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html