Results 1 to 5 of 5

Thread: getting webbrowser data to text file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    22

    getting webbrowser data to text file

    hello i am from vb6 and there is a text that is header between <h1>header</h1> and i wnana get that header into text box but how ???
    help me

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: getting webbrowser data to text file

    Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB6 and earlier' forum

  3. #3
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: getting webbrowser data to text file

    In which continent is VB6?

    To get the data from header, use the webbrowser/internet explorer Document (DOM), very easy.

    Quick example:

    -Add 1 CommandButton "Command1"
    -Add 1 WebBrowser "WebBrowser1"
    Code:
    Private Sub Command1_Click()
    Debug.Print WebBrowser1.Document.body.innerhtml
    End Sub
    
    Private Sub Form_Load()
    WebBrowser1.Navigate "www.google.com"
    End Sub

  4. #4
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: getting webbrowser data to text file

    Private Function GetBetween(ByRef sSearch As String, _
    ByRef sStart As String, _
    ByRef sStop As String, _
    Optional ByVal lSearch As Long = 1, _
    Optional ByVal bCaseSensitive As Boolean = True) As String

    Dim lonS As Long, lonE As Long
    Dim strLCSearch As String
    Dim strLCStart As String, strLCStop As String

    'Case-sensitive...
    If bCaseSensitive Then
    lonS = InStr(lSearch, sSearch, sStart)
    If lonS Then
    lonS = lonS + Len(sStart)
    lonE = InStr(lonS, sSearch, sStop)
    If lonE Then
    GetBetween = Mid$(sSearch, lonS, lonE - lonS)
    End If
    End If

    'Not case-sensitive
    'Faster to convert string to lowercase rather than vbTextCompare
    Else
    strLCSearch = LCase$(sSearch)
    strLCStart = LCase$(sStart)
    strLCStop = LCase$(sStop)
    lonS = InStr(lSearch, strLCSearch, strLCStart)
    If lonS Then
    lonS = lonS + Len(strLCStart)
    lonE = InStr(lonS, strLCSearch, strLCStop)
    If lonE > 0 Then
    GetBetween = Mid$(sSearch, lonS, lonE - lonS)
    End If
    End If
    End If
    End Function

    Private Sub Command1_Click()
    'Not case-sensitive

    Text2.Text = GetBetween(WebBrowser1.Document.body.innerhtml, "<h1>", "</h1>" 'Case-sensitive

    End Sub
    good luck

  5. #5
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: getting webbrowser data to text file

    Quote Originally Posted by Max187Boucher View Post
    In which continent is VB6?
    The original poster is asking how to retrieve text from between <h1> </h1> tags not the header of the actual web page.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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