
正文
vb.net下载网页源码 vb获取网页源码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.NET 不使用控件获取某网页源代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyClient As Net.WebClient = New Net.WebClient
Dim MyReader As New System.IO.StreamReader(MyClient.OpenRead(""), System.Text.Encoding.Default)
Dim MyWebCode As String = MyReader.ReadToEnd
Me.RichTextBox1.Text = MyWebCode
MyReader.Close()
End Sub
相关问答
Q1: 如何用vb.net获取网页源代码
使用webbrowser控件来加载网页,然后再
Private
Sub
WebBrowser
1_DocumentCompleted下通过使用WebBrowser1.Document.Body.
InnerHtml
来获取网页的源代码,或使用
WebBrowser1.Document.Body.InnerText来获取网页中的文本。之后可以通过字符串控制指令或者
正则表达式
来精确获取到你所需的数据。
Q2: vb.net HttpWebResponse和HttpWebRequest 下载网页源代码 如何等待网页加载完毕在在下?
在HttpWebRequest.GetResponse运行完毕之后,就表示网页已经加载完毕了。
如果是异步获取HttpWebResponse,那么在HttpWebRequest.EndGetResponse之后也表示网页加载完毕了。
Q3: 用VB快速下载[网页源代码]
后台下载
声明vb.net下载网页源码:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
'//调用
然后在代码里直接调用vb.net下载网页源码:
Call URLDownloadToFile(0, "网页地址", "保存到本地文件名和地址", 0, 0)
如
Call URLDownloadToFile(0, "", "c:\1.htm", 0, 0)
相当于另存为
声明vb.net下载网页源码:
Private Declare Function DoFileDownload Lib "shdocvw.dll"(ByVal lpszFile As String) As Long
'//调用
然后在代码里直接调用vb.net下载网页源码:
Dim gourl As String
AdUrl = StrConv("网页地址", vbUnicode)
Call DoFileDownload(gourl)
Q4: 如何用vb.net获得网页的源代码
Dim url As String=" 网址"
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与
Internet资源建立持久连接。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码
Q5: VB下载网页源码
使用 URLDownloadToFile 这个API可以实现你想要的功能。
'// 定义
'// 下载网络上的一个文件到本地
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long _
) As Long
'// 下载一个文件到本地
Public Function DownloadFile(ByVal strURL As String, ByVal strFile As String) As Boolean
Dim lngReturn As Long
lngReturn = URLDownloadToFile(0, strURL, strFile, 0, 0)
If lngReturn = 0 Then DownloadFile = True
End Function
Private Sub Command1_Click()
Debug.Print DownloadFile("", "D:\1.html")
End Sub
关于vb.net下载网页源码和vb获取网页源码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








