Issue
I like to use MSXML2.ServerXMLHTTP.6.0 when I can as it is faster. However, I have not been able to figure out how to use it when I need to interact with the website. Thats probably for another question.
However, I am having an issue on why I get different URL returned. When I use the following code, I get the required results ...
Sub GoogleSfund()
Set objIExplorer = New InternetExplorerMedium
objIExplorer.Silent = True
objIExplorer.Visible = False 'for testing change to true
objIExplorer.Navigate "https://www.google.com/search?q=DWCPF"
Do While objIExplorer.Busy or Not objIExplorer.ReadyState = 4: DoEvents: Loop
a = objIExplorer.Document.body.getElementsByTagName("g-card-section")
pos1 = InStr(a.innerText, "INDEXDJX: DWCPF")
pos2 = InStr(a.innerText, "Disclaimer")
b = Mid(a.innerText, pos1, pos2 - pos1)
b = Replace(b, vbCrLf & vbCrLf, vbCrLf)
MsgBox b
TSP_Test.lblSfund.Caption = b
objIExplorer = ""
End Sub...
With (MSXML2.ServerXMLHTTP.6.0) it does not grab the page with the same URL
Sub GoogleSfundFAST()
Dim sSourceUrl As String
Dim HttpReq as Object
Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP.6.0")
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLH3Doc As New MSHTML.HTMLDocument
Dim HTMLInstProcDoc As New MSHTML.HTMLDocument
sSourceUrl = "https://www.google.com/search?q=dwcpf"
'sSourceUrl = "https://www.google.com/search"
HttpReq.Open "GET", sSourceUrl, False
HttpReq.send
If HttpReq.Status = 200 Then
HttpReq.getAllResponseHeaders
HTMLDoc.body.innerHTML = HttpReq.responseText
End If
Dim Obj As MSHTML.HTMLGenericElement
Dim Heading As MSHTML.IHTMLElementCollection
Dim HD As HTMLElementCollection
Debug.Print HTMLDoc.body.innerHTML
End Sub
Any Ideas why it is different?
Solution
As indicated in the comment below Tim lead me to the answer. Which was using the Chrome Developer Tools
Answered By - Rjtaylor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.