【发布时间】:2014-09-14 11:44:35
【问题描述】:
我已经编写了整个代码来从网站中提取手机号码 但问题是它完美地提取数字但非常缓慢它还在提取时挂起我的表单,请帮助我让它运行得更快。
更高效地运行。
Imports HtmlAgilityPack
Imports System.Text.RegularExpressions
Public Class Extractor
Shared doc As New HtmlAgilityPack.HtmlDocument()
Public Shared Function ScrapLinks(TextBox1 As TextBox, ListBox1 As ListBox, lbllinks As Label)
Dim hw As New HtmlWeb()
Try
doc = hw.Load(TextBox1.Text)
doc.LoadHtml(doc.DocumentNode.SelectSingleNode("//*[@id='ad_list']").InnerHtml())
For Each link As HtmlNode In doc.DocumentNode.SelectNodes("//a[@href]")
Dim hrefValue As String = link.GetAttributeValue("href", String.Empty)
If hrefValue.Contains("/detail/") Then
If Not ListBox1.Items.Contains(hrefValue) Then
ListBox1.Items.Add(hrefValue)
End If
End If
Next
Catch ex As Exception
MsgBox("Error " + ex.Message)
End Try
Return Nothing
End Function
Public Shared Function Scrapnums(lstbox As ListBox,lstnum As ListBox)
Try
Dim hw As New HtmlWeb()
doc = hw.Load(lstbox.SelectedItem)
Dim data = doc.DocumentNode.SelectSingleNode("//*[@class='det_ad f_left']").InnerText
Dim m As Match = Regex.Match(data, "(\+92|0092)-?\d{3}-?\d{7}|\d{11}|\d{4}-\d{7}")
If Not lstnum.Items.Contains(m.Value) Then
lstnum.Items.Add(m.Value)
End If
Catch ex As Exception
End Try
Return Nothing
End Function
End Class
【问题讨论】:
-
我在codereview上问过问题 谢谢参考!
-
我设法为您刚刚删除的问题创建了一个可能的正则表达式。
-
@pushpraj 很抱歉,但我感觉很糟糕,因为我的问题有些低分。
-
@pushpraj 请在此处发布您的正则表达式!请。