Results 1 to 11 of 11

Thread: Get HTML from webpage w/o Inet

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Philadelphia, PA
    Posts
    120

    Get HTML from webpage w/o Inet

    Hi there,

    What is another way to download the page source code w/o using the Inet control?

    Can a webbrowser control be used to do this? If so, please provide an example.

    ex.:
    strURL = "http://yahoo.com"

    All i need is the source code of strURL put into strHTML without using the Inet control.

    Thanks in advance!

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Get HTML from webpage w/o Inet

    Why not use Inet?

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Get HTML from webpage w/o Inet

    You can use XML in addition to Winsock to get html code.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  With Winsock
    5.     .RemoteHost = "finance.lycos.com"
    6.     .RemotePort = 80
    7.     .Close
    8.     .Connect
    9.  End With
    10. End Sub
    11.  
    12. Private Sub Winsock_Connect()
    13.     Winsock.SendData "GET /qc/stocks/quotes.aspx?symbols=INTC" & Chr(10)
    14. End Sub
    15.  
    16. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    17. Dim X As String
    18.     Winsock.GetData X
    19.     Debug.Print X
    20. End Sub
    21.  
    22. Private Sub Winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    23. Debug.Print "Error "; Description
    24. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Philadelphia, PA
    Posts
    120

    Re: Get HTML from webpage w/o Inet

    You see the webpage im trying to parse data from is special lol...

    When i try to use inet to download html from it, it detects it as data mining or something and takes me to an error page and then my program displays the html of that error page...

    so, what i need to do is create a webbrowser control, load the page in there and only then get the html from an already loaded page within my webbrowser control.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Get HTML from webpage w/o Inet

    Did you see my post?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Philadelphia, PA
    Posts
    120

    Re: Get HTML from webpage w/o Inet

    yeh im still trying to figure out how to use it

    in your example above, is this what actually gets the html?
    VB Code:
    1. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    2. Dim X As String
    3.     Winsock.GetData X
    4. End Sub

    maybe there is an easier way? How would i get InnerHTML from webbrowser1... trying to do some research on this, haven't found anything useful yet.


    - lol.. laptop is dieing, hope i figure this out before 8% of my battery runs out
    Last edited by Nervotrep; Aug 6th, 2005 at 12:54 PM.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Get HTML from webpage w/o Inet

    WebBrowser1.Document.Body.parentElement.innerHTML

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Get HTML from webpage w/o Inet

    VB Code:
    1. '' Jamie Plenderleith
    2. '' [url]http://www.plenderj.com[/url]
    3. ''
    4. Public Function strGetHTMLBasic(ByVal strURI As String, ByVal strCustomPOSTData As String) As String
    5.         Dim objWebClient As HttpWebRequest = WebRequest.Create(strURI)
    6.         If Not strCustomPOSTData = vbNullString Then
    7.             Dim encoding As New ASCIIEncoding(), bteLength As Byte()
    8.             strCustomPOSTData = EnsureHTTPEncoded(strCustomPOSTData)
    9.             With objWebClient
    10.                 .Method = "POST"
    11.                 .ContentType = "application/x-www-form-urlencoded"
    12.                 bteLength = encoding.GetBytes(strCustomPOSTData)
    13.                 .ContentLength = bteLength.GetLength(0)
    14.                 Dim stmRequestWriter As New StreamWriter(.GetRequestStream, encoding.ASCII)
    15.                 stmRequestWriter.Write(strCustomPOSTData)
    16.                 stmRequestWriter.Close()
    17.             End With
    18.         End If
    19.         Dim stmStreamReader As New StreamReader(objWebClient.GetResponse.GetResponseStream)
    20.         Dim strRetVal As String = stmStreamReader.ReadToEnd
    21.         stmStreamReader.Close() : Return strRetVal
    22.     End Function
    23.  
    24.     Function EnsureHTTPEncoded(ByVal strString As String) As String
    25.         Dim strRetVal As String
    26.         If Not strString = vbNullString Then
    27.             If Not InStr(strString, "&") = 0 Then
    28.                 Dim strArr() As String = Split(strString, "&")
    29.                 Dim strTemp As String, strTempArr() As String
    30.                 For Each strTemp In strarr
    31.                     strTempArr = Split(strTemp, "=")
    32.                     strRetVal &= HTTPEncode(strTempArr(0)) & "=" & HTTPEncode(strTempArr(1)) & "&"
    33.                 Next
    34.                 If Right(strRetVal, 1) = "&" Then strRetVal = Left(strRetVal, Len(strRetVal) - 1)
    35.             Else
    36.                 Dim strArr() As String = Split(strString, "=")
    37.                 strRetVal = HTTPEncode(strarr(0)) & "=" & HTTPEncode(strarr(1))
    38.             End If
    39.         End If
    40.         Return strRetVal
    41.     End Function
    42.  
    43.     Function HTTPEncode(ByVal strString As String) As String
    44.         Return HttpUtility.UrlEncode(strString)        
    45.     End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Get HTML from webpage w/o Inet

    Jamie, there's no StreamReader in Classic VB

  10. #10
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Get HTML from webpage w/o Inet

    lol. Assumed this was .NET because the last post I saw about screen scraping had you in it too
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  11. #11
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Get HTML from webpage w/o Inet

    Erm. Why not just use URLDownloadToFile? Search the forums, its an API. Download the source to your computer and load it in locally.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width