[RESOLVED] Find a string in a webpage-VBForums
Results 1 to 2 of 2

Thread: [RESOLVED] Find a string in a webpage

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Scotland, UK

    Resolved [RESOLVED] Find a string in a webpage

    Hello. I was wondering how to find a string in a webpage.

    say i opened a website and i want to check if it contains a string e.g. "glasgow rangers" and if it contained that then my computer will beep.

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Inside the CPU...

    Re: Find a string in a webpage

    Put a webbrowser control on your page.

    YOu can navigate to the desired page by calling the Navigate method:
    vb Code:
    1. WebBrowser1.Navigate "http://www.mywebsite.com"

    You can get the InnerText and see if it contains what you want:
    vb Code:
    1. Dim PageText As String
    2. Dim SearchText as String
    3. SearchText = "glasgow rangers"
    4. PageText = WebBrowser1.Document.Body.InnerText
    5. If InStr(PageString, SearchText) > 0 Then
    6.     Msgbox "Found"
    7. Else
    8.     MsgBox "Not Found"
    9. End If

    NB: None of the above code is tested. I just typed it here, so it might have spelling mistakes too. The sole intention was to make you understand how to go about it. Please let me know if something doesn't work.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." Charles F. Kettering

    Read articles on My Blog 101 LINQ Samples JSON Validator XML Schema Validator "How Do I" videos on MSDN VB.NET and C# Comparison Good Coding Practices VBForums Reputation Saver String Enum Super Simple Tetris Game

    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Tags for this Thread

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