login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > .NET > VB.NET > Download and scan a webpage

Download and scan a webpage

Auteur: Mario - 12 januari 2010 - 11:03 - Gekeurd door: Mario - Hits: 2997 - Aantal punten: 4.50 (1 stem)





De onderstaande code zal een webpagina inlezen waarna we de input gaan scannen via regex op een zoekterm (in dit geval op geldige url's).

Via de download button kun je een werkend voorbeeld in vb.net uitproberen.

mvg,
Mario

Code:
  1. Imports System.Text.RegularExpressions
  2.  
  3. Public Class Form1
  4.  
  5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.  
  7. TextBox1.Clear() : TextBox2.Clear()
  8. Dim MyWebClient As New System.Net.WebClient()
  9.  
  10. '// --------------------------------------------------
  11. '// Enkel als je achter een proxy zit !!!
  12. '// Anders mag je de code hieronder in
  13. '// commentaar zetten
  14. '// --------------------------------------------------
  15. Dim MyCredentials As New Net.NetworkCredential
  16. With MyCredentials
  17. .UserName = "**********"
  18. .Password = "**********"
  19. End With
  20.  
  21. Dim MyWebProxy As New Net.WebProxy
  22. With MyWebProxy
  23. .Address = New Uri("***********************")
  24. .Credentials = MyCredentials
  25. .BypassProxyOnLocal = True
  26. End With
  27.  
  28. MyWebClient.Proxy = MyWebProxy
  29. '// --------------------------------------------------
  30.  
  31. TextBox1.Text = MyWebClient.DownloadString("http://www.sitemasters.be")
  32.  
  33. '// Via Regex alle gevonden url's in een textbox stoppen
  34.  
  35. Dim RegexPattern As String = "http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?"
  36.  
  37. Dim mobileRegex As Regex = New Regex(RegexPattern)
  38. Dim allMatches As MatchCollection = mobileRegex.Matches(TextBox1.Text)
  39. For Each match As Match In allMatches
  40. TextBox2.Text &= match.Value & vbCrLf
  41. Next
  42.  
  43. End Sub
  44.  
  45.  
  46. End Class
Download code! Download code (.txt)

Download dit script! Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (5)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.018s