asp.net(VB)中使用正则获取图片地址并进行下载.
来源:互联网 发布:无线淘宝logo尺寸 编辑:程序博客网 时间:2024/05/29 13:24
使用时需要导入.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
- asp.net(VB)中使用正则获取图片地址并进行下载.
- ASP.NET C#获取文章中图片的地址
- asp.net 获取html代码中图片的URL地址
- asp.net 获取GridView中a标签并进行操作
- ASP获取网页全部图片地址并保存为数组的正则
- ASP.NET动态生成图片并下载
- 上传图片并生成缩略图(ASP.NET+VB.NET)
- 如何在asp.net中使用百度地图并动态获取到数据库中的坐标点进行标注
- ASP.Net中使用VB.Net调用存储过程并得到返回值
- ASP.Net中使用VB.Net调用存储过程并得到返回值
- ASP.Net中使用VB.Net调用存储过程并得到返回值
- ASP.Net中使用VB.Net调用存储过程并得到返回值
- 正则获取图片地址
- 正则获取图片地址
- VB.NET 获取IP地址
- VB.NET获取MAC地址
- Vb.net 获取IP地址
- Asp.net判断图片存在的并获取图片
- Android开发之AppWidget应用(一)
- Qtablewidget / Qtableview
- PHP常见函数整理
- Android开发之AppWidget应用(二)
- asp.net组件开发(C #) 一
- asp.net(VB)中使用正则获取图片地址并进行下载.
- asp.net组件开发(C #) 二 代码解析
- Android开发之多点触控
- linux系统网络设置
- asp.net组件开发(C #) 三 一个复杂点的控件
- 用指针方式实现strcat(s,t)函数
- 锁屏界面
- CREATE DISKGROUP
- 举个例子