Results 1 to 3 of 3

Thread: search IE

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    51

    Question search IE

    ok im trying to make a program that searches a page in IE for a keyword then beeps me if it has found it or refreshes the page then searches again if it hasnt found it but i do not no how to search for a keyword any help would be apreciated

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    51

    Re: search IE

    anyone ?

  3. #3
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: search IE

    This is from the microsoft website which will return all URLs from a website, perhaps with a little tweeking of the reg ex it could fit your purpose.
    VB Code:
    1. Imports System.Net
    2. Imports System.IO
    3. Imports System.Text.RegularExpressions
    4.  
    5. Public Module ExtractURITest
    6.  
    7.     Public Sub Main()
    8.         Console.WriteLine("Enter a URL, and press Enter (must start with http://).")
    9.         Dim Url As String = Console.ReadLine()
    10.  
    11.         Dim BaseUri As Uri
    12.         Dim Page As String
    13.         Try
    14.             BaseUri = New Uri(Url)
    15.  
    16.             ' Create the request.
    17.             Dim PageRequest As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
    18.  
    19.             ' Get the response.
    20.             ' This takes the most significant amount of time, particularly
    21.             ' if the file is large, because the whole response is retrieved.
    22.             Dim PageResponse As WebResponse = PageRequest.GetResponse()
    23.             Console.WriteLine("Response received.")
    24.  
    25.             ' Read the response stream.
    26.             Dim r As New StreamReader(PageResponse.GetResponseStream())
    27.             Page = r.ReadToEnd()
    28.             r.Close()
    29.  
    30.         Catch Err As Exception
    31.             Console.WriteLine(Err.ToString())
    32.             Console.ReadLine()
    33.             Return
    34.         End Try
    35.  
    36.         ' Define the regular expression.
    37.         Dim HrefPattern As String = "href\s*=\s*(?:""(?<match>[^""]*)""|(?<match>\S+))"
    38.         'Dim HrefPattern As String = "href\s*=\s*""(?<match>[url]http://.*?[/url])"""
    39.  
    40.         Dim HrefRegex As New Regex(HrefPattern, _
    41.           RegexOptions.IgnoreCase Or RegexOptions.Compiled)
    42.  
    43.         ' Find and display all the href matches.
    44.         Dim HrefMatch As Match = HrefRegex.Match(Page)
    45.         Do While HrefMatch.Success
    46.             Dim Link As String = HrefMatch.Groups(1).Value
    47.  
    48.             If Link.Substring(0, 1) = "#" Then
    49.                 ' Ignore this match, it was just a bookmark.
    50.             Else
    51.                 ' Attempt to determine if this is a fully-qualified link
    52.                 ' by comparing it against some known schemes.
    53.                 Dim Absolute As Boolean = False
    54.                 If Link.Length > 8 Then
    55.                     Dim Scheme As String
    56.                     Scheme = Uri.UriSchemeHttp & "://"
    57.                     If Link.Substring(0, Scheme.Length) = Scheme Then Absolute = True
    58.                     Scheme = Uri.UriSchemeHttps & "://"
    59.                     If Link.Substring(0, Scheme.Length) = Scheme Then Absolute = True
    60.                     Scheme = Uri.UriSchemeFile & "://"
    61.                     If Link.Substring(0, Scheme.Length) = Scheme Then Absolute = True
    62.                 End If
    63.  
    64.                 ' (You could compare it against additional schemes here.)
    65.  
    66.                 If Absolute Then
    67.                     Console.WriteLine(Link)
    68.                 Else
    69.                     Console.WriteLine(New Uri(BaseUri, Link).ToString())
    70.                 End If
    71.             End If
    72.             HrefMatch = HrefMatch.NextMatch()
    73.         Loop
    74.  
    75.         Console.ReadLine()
    76.  
    77.     End Sub
    78.  
    79. End Module

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