Reputation: 3
I want to extract response body of a webpage. The information I need is in the response body of page 43 out of 60. I tried using another solution which gives me some Chinese texts from the response body (I guess it is encrypted).
I tried some code which gives me response text which is not a requirement here. You can check the response body of page in developer tools-->network-->details-->response body.
It loads only when you click on network traffic capturing button and then refresh the page. It will track all the requests and responses.
How do I get the Response body (not response text) from the webpage using VBA?
Upvotes: 0
Views: 4582
Reputation: 11
this is the code which gives me first response body but want to loop through all response bodies of a web page.
Sub HTMLsearch()
Dim Html As String
Html = GetHTML("https://portal.mylink.com/vspace/")
' Cyrillic characters are supported in Office, so they will appear correctly
rsbody= Html
End Sub
Function GetHTML(Url As String) As String
Dim request As Object
Set request = CreateObject("Msxml2.XMLHTTP.3.0")
Dim converter As New ADODB.stream
' fetch page
request.Open "GET", Url, False
request.send
' write raw bytes to the stream
converter.Open
converter.Type = adTypeBinary
converter.Write request.ResponseBody
' read text characters from the stream
converter.Position = 0
converter.Type = adTypeText
converter.Charset = "Windows-1251"
' set return value, close the stream
GetHTML = converter.ReadText
converter.Close
End Function
Upvotes: 1