Private Function GetPictureUrls(ByVal url As String) As ArrayList Dim html As String Dim pageAddress As Uri Dim match As Match Dim matches As MatchCollection Dim imgsrc, imgFullUrl As String Dim ext As String Dim pictures As New ArrayList pageAddress = New Uri(url) html = GetHtml(url, "") matches = Regex.Matches(html, "<img.*?src\s*?=\s*[""|']?(?<imgsrc>[^""'>]*)[""|']?.*?>", RegexOptions.IgnoreCase) For Each match In matches imgsrc = match.Result("${imgsrc}") ext = Path.GetExtension(imgsrc) If ext <> "" AndAlso txtImageTypes.Text.IndexOf(ext) > -1 Then If imgsrc.ToLower().StartsWith("http://") Then imgFullUrl = imgsrc ElseIf imgsrc.StartsWith("/") Then imgFullUrl = pageAddress.Host & imgsrc Else imgFullUrl = Path.GetDirectoryName(pageAddress.AbsolutePath) & "/" & imgsrc End If If Not pictures.Contains(imgFullUrl) AndAlso Not m_Pictures.Contains(imgFullUrl) Then pictures.Add(imgFullUrl) m_Pictures.Add(imgFullUrl) End If End If Next matches = Nothing pageAddress = Nothing Return pictures End Function从我写的一个下载网页上所有图片的小程序上摘下来的,需要完整代码(2003项目)的留下email,本来想放在我的网站空间上的,可惜网站挂了
^\w+(\.[jpg]+)+$
是不行的,不过谢谢
string src = Regex.Match(imgHtml,"src=([0]|[^0])*?( |>)",RegexOptions.IgnoreCase).Value;
src = src.Replace("src=","").Replace("\"","").Replace("'","");
src = src.Substring(0,src.Length-1);
Dim html As String
Dim pageAddress As Uri
Dim match As Match
Dim matches As MatchCollection
Dim imgsrc, imgFullUrl As String
Dim ext As String
Dim pictures As New ArrayList pageAddress = New Uri(url)
html = GetHtml(url, "")
matches = Regex.Matches(html, "<img.*?src\s*?=\s*[""|']?(?<imgsrc>[^""'>]*)[""|']?.*?>", RegexOptions.IgnoreCase) For Each match In matches
imgsrc = match.Result("${imgsrc}")
ext = Path.GetExtension(imgsrc)
If ext <> "" AndAlso txtImageTypes.Text.IndexOf(ext) > -1 Then
If imgsrc.ToLower().StartsWith("http://") Then
imgFullUrl = imgsrc
ElseIf imgsrc.StartsWith("/") Then
imgFullUrl = pageAddress.Host & imgsrc
Else
imgFullUrl = Path.GetDirectoryName(pageAddress.AbsolutePath) & "/" & imgsrc
End If If Not pictures.Contains(imgFullUrl) AndAlso Not m_Pictures.Contains(imgFullUrl) Then
pictures.Add(imgFullUrl)
m_Pictures.Add(imgFullUrl)
End If
End If
Next matches = Nothing
pageAddress = Nothing Return pictures
End Function从我写的一个下载网页上所有图片的小程序上摘下来的,需要完整代码(2003项目)的留下email,本来想放在我的网站空间上的,可惜网站挂了