Get links on the web with regular expressions

xiaoxiao2021-03-06  75

Enter an address, you can extract the links in that web page. The following code can be easily implemented, mainly to use the regular expression. View example http://search.9cbs.net/expert/topic/2131/2131209.xml?temp=.4868585

The geturl.aspx code is as follows:

<% @ Page language = "vb" codebehind = "geturl.aspx.vb" autoeventwireup = "false" inherits = "aspxweb.geturl"%>

http://lucky_love.www1.dotNetPlayground.com/


Post Code geturl.aspx.vb as follows:

Imports system.iimports system.netimports system.text.RegularExpressionsimports System

Public Class GetUrl Inherits System.Web.UI.Page Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents urlTextBox As System.Web.UI.WebControls.TextBox Protected WithEvents scrapeButton As System.Web.UI.WebControls.Button Protected Withevents TipResult As System.Web.ui.WebControls.Label Protected WitHevents Resultlabel as system.Web.ui.WebControls.TextBox # Region "Web Form Designer Generated Code"

'This call is required for the web form designer. private subinitializecomponent ()

End Sub

Private Sub Page_init (Byval E AS System.EventArgs) Handles mybase.init 'Codegen: This method call is required by the Web Form Designer' Do not modify it using the code editor. InitializationComponent () End Sub

#End region

Private Sub Page_Load (Byval E AS System.EventArgs) Handles mybase.load 'Place the initialization page here's user code Label1.Text = "Please enter a URL address:" ScrapeButton.Text = "separation HREF Link "End Sub Private Report As New StringBuilder () Private WebPage As String Private Countofmatches as Int32

Public Sub ScrapeButton_Click (Byval E AS System.EventArgs) WebPage = Graburl () Dim MyDelegate As New Matchevaluator (Addressof Matchhandler)

DIM LINKSEXPIRESSION As New Regex (_ "/ "a. ?href=['""](? !http/:/:) (,foundanchovels [^'"">] ?) [^>] *? />, _ Regexoptions.multiline or regexoptions.ignorecase or regexoptions.ignorepatternwhitespace)

Dim newwebpage as string = linksexpression.replace (webpage, mydelegate)

TipResult.text = "

HREF link from" & URLTextBox.text & "finds and organizes" & countofmatches.toString () & "link

"& _ report.ToString (). Replace (Environment.NewLine,"
") TipResult.Text & ="

finishing off the page