1、相关代码如下: Public Function getHtmlStr(strUrl As String) '获取远程网页源码 On Error Resume Next Dim XmlHttp As Object, stime, ntime Set XmlHttp = CreateObject("Microsoft.XMLHTTP") XmlHttp.open "GET", strUrl, True XmlHttp.send stime = Now '获取当前时间 While XmlHttp.ReadyState <> 4 DoEvents ntime = Now '获取循环时间 If DateDiff("s", stime, ntime) > 3 Then getHtmlStr = "": Exit Function Wend getHtmlStr = StrConv(XmlHttp.responseBody, vbUnicode) Set XmlHttp = Nothing End Function 2、代码使用:在窗体代码相应位置写如下代码 dim a as string a=getHtmlStr("要获取的网站网址url") 上面a取得的值就是我们要的结果。 |
转载请注明:VB编程» VB获取网页内容方法,VB读取网页内容
标签: