Download HTML-source with

Paste in a module and just call the function like this:
HelloString = GetHTML(“”)

Private requestweb As HttpWebRequest
Private responseWeb As HttpWebResponse

Public Function GetHTML(ByVal URL)
Dim WebSource As String = ""
Dim objStreamReader As StreamReader = Nothing

requestweb = CType(WebRequest.Create(URL), HttpWebRequest)
With requestweb
.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
.Method = "GET"
.Timeout = 10000
End With

responseWeb = CType(requestweb.GetResponse(), HttpWebResponse)
Catch ex As Exception
MessageBox.Show("Error retrieving the Web page " & _
"you requested. Please check the entered Url and your internet connection")
Exit Function
End Try

If Not IsNothing(responseWeb.GetResponseStream()) Then
'objStreamReader = New StreamReader(responseWeb.GetResponseStream())
objStreamReader = New StreamReader(responseWeb.GetResponseStream(), Encoding.UTF8)
WebSource = objStreamReader.ReadToEnd
Catch ex As Exception
Exit Function
End Try

End If
Return (WebSource)
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *