asp.net(VB)中使用正则获取图片地址并进行下载.
2011-09-19 14:47
806 查看
使用时需要导入.net命名空间,本例对复制到文本框中的网页源代码获取其中图片地址,并下载,你也可以根据需要把图片在你的页面上进行显示.
Imports System.Net
Partial Class Query_QImage
Inherits System.Web.UI.Page
Function Htmlimg(ByVal str As String) As String
Dim Himg As String = ""
Dim rg As Regex
rg = New Regex("<img.+?>")
Dim mm = rg.Matches(str)
For Each Match1 In mm
Himg = Himg & Getimgs(Match1.value)
Next
Return Himg
End Function
Function Getimgs(ByVal str As String) As String
Dim Gimgs As String = ""
Dim rg As Regex
rg = New Regex("http://([^']+(?:jpg""|gif""|png""|bmp""|jpeg""))") '("http://.+?.jpg""")
Dim mm = rg.Matches(str)
For Each Match1 In mm
Gimgs = Gimgs & "|" & Left(Match1.Value, Len(Match1.Value) - 1)
Next
Return Gimgs
End Function
'对代码中的图片进 行下载,保存到d盘,指定的路径一定要存在.
Protected Sub btn_down_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_down.Click
Dim wc As New WebClient
Dim imgs As String '所有图片的地址
'Dim imgdata As Byte() ' imgdata = wc.DownloadData(url) 'Response.BinaryWrite(imgdata)
Dim path As String = "D:\Test\"
Dim Fname As String = "" '图片的名称
Dim url As String = "" '图片的url地址
Dim img() As String
Dim sx() As String
Dim sss As String = ""
imgs = Htmlimg(txt_lr.Text)
img = Split(imgs, "|")
txt_lr.Text = imgs
For Each ss In img
url = ss
sx = Split(ss, "/")
Fname = sx(sx.Length - 1)
If Fname = "" Then
Else
sss += path & Fname
wc.DownloadFile(url, path & Fname)
End If
Next
txt_lr.Text = sss
End Sub
Imports System.Net
Partial Class Query_QImage
Inherits System.Web.UI.Page
Function Htmlimg(ByVal str As String) As String
Dim Himg As String = ""
Dim rg As Regex
rg = New Regex("<img.+?>")
Dim mm = rg.Matches(str)
For Each Match1 In mm
Himg = Himg & Getimgs(Match1.value)
Next
Return Himg
End Function
Function Getimgs(ByVal str As String) As String
Dim Gimgs As String = ""
Dim rg As Regex
rg = New Regex("http://([^']+(?:jpg""|gif""|png""|bmp""|jpeg""))") '("http://.+?.jpg""")
Dim mm = rg.Matches(str)
For Each Match1 In mm
Gimgs = Gimgs & "|" & Left(Match1.Value, Len(Match1.Value) - 1)
Next
Return Gimgs
End Function
'对代码中的图片进 行下载,保存到d盘,指定的路径一定要存在.
Protected Sub btn_down_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_down.Click
Dim wc As New WebClient
Dim imgs As String '所有图片的地址
'Dim imgdata As Byte() ' imgdata = wc.DownloadData(url) 'Response.BinaryWrite(imgdata)
Dim path As String = "D:\Test\"
Dim Fname As String = "" '图片的名称
Dim url As String = "" '图片的url地址
Dim img() As String
Dim sx() As String
Dim sss As String = ""
imgs = Htmlimg(txt_lr.Text)
img = Split(imgs, "|")
txt_lr.Text = imgs
For Each ss In img
url = ss
sx = Split(ss, "/")
Fname = sx(sx.Length - 1)
If Fname = "" Then
Else
sss += path & Fname
wc.DownloadFile(url, path & Fname)
End If
Next
txt_lr.Text = sss
End Sub
相关文章推荐
- Python---对html文件内容进行搜索取出特定URL地址字符串,保存成列表,并使用每个url下载图片,并保存到硬盘上,使用正则re
- Python---对html文件内容进行搜索取出特定URL地址字符串,保存成列表,并使用每个url下载图片,并保存到硬盘上,使用bs4,beautifulsoup模块
- ASP获取网页全部图片地址并保存为数组的正则
- ASP.NET/C#获取文章中第一张图片的地址
- asp.net 后台获取flv视频地址进行播放【转】
- Asp.net 获取图片列表并打包下载
- ASP获取网页全部图片地址并保存为数组的正则
- asp.net 获取html代码中图片的URL地址
- VB.net中使用正则表达式验证邮箱地址是否合法
- 如何在asp.net中使用百度地图并动态获取到数据库中的坐标点进行标注
- C# ASP.NET 走火入魔通用权限管理系统组件V3.2试用版下载地址【含数据库设计文档、使用手册】
- asp.net中获取全文图片地址的方法
- asp.net 后台获取flv视频地址进行播放
- ASP使用正则表达式批量分离编辑框中的图片从而获取图片路径
- FCKeditor是使用非常广泛的HTML编辑器,本文从 ASP.NET 的使用场景对 FCKeditor 与 FCKeditor.NET 的配置、功能扩展(如自定义文件上传子目录、自定义文件名、上传图片的后期处理等)、以及安全性进行初步的阐述。
- asp.net 把图片压缩成zip之后再进行下载
- ASP.NET C#获取文章中图片的地址
- ASP使用正则表达式获得代码中第一张图片地址
- ASP获取网页全部图片地址并保存为数组的正则
- C# ASP.NET 走火入魔通用权限管理系统组件V3.2试用版下载地址【含数据库设计文档、使用手册】