VB6.0获取网页源代码 - 木子屋 和另外 4 个页面 - 用户配置 1
VB6.0获取网页源代码编辑:dnawo 日期:2009-09-28字体大小: 小 中 大
复制内容到剪贴板程序代码'说明:获取网页源代码'参数:' url: 链接地址' encoding: 页面编码,gb2312、utf-8等Public Function GetResponse(ByVal url As String, ByVal encoding As String) As StringDim xmlHTTP As ObjectDim content As VariantOn Error Resume NextSet xmlHTTP = CreateObject("Microsoft.XMLHTTP")xmlHTTP.Open "GET", url, TruexmlHTTP.sendWhile xmlHTTP.readyState <> 4DoEventsWendcontent = xmlHTTP.responseBodyIf CStr(content) <> "" Then GetResponse = EncodingConvertor(content, encoding)Set xmlHTTP = NothingIf Err.Number <> 0 ThenGetResponse = ""End IfOn Error GoTo 0End Function'说明:字符串编码转换'参数:' content: 文本' encoding:编码Public Function EncodingConvertor(ByVal content As Variant, ByVal encoding As String) As StringDim objStream As ObjectOn Error Resume NextSet objStream = CreateObject("Adodb.Stream")With objStream.Type = 1.Mode = 3.Open.Write content.Position = 0.Type = 2.Charset = encodingEncodingConvertor = .ReadText.CloseEnd WithSet objStream = NothingIf Err.Number <> 0 ThenEncodingConvertor = ""End IfOn Error GoTo 0End Function'获取指定页面源代码Private Sub Command1_Click()Text1.Text = GetResponse("http://www.mzwu.com/", "utf-8")End Sub