Vb6 下载网页

 Dim xmlHtppDownPage As XMLHTTP

Public Function DownPage(ByVal strUrl As String) As String
    DownPage = ""
    On Error GoTo error1:
    If xmlHtppDownPage Is Nothing Then
        Set xmlHtppDownPage = New XMLHTTP
    End If
   
    xmlHtppDownPage.open "GET", strUrl, False
    xmlHtppDownPage.send
    If xmlHtppDownPage.Status <> 200 Then
        Exit Function
    End If
    DownPage = BytesToBstr(xmlHtppDownPage.responseBody, "GB2312")
    Exit Function
error1:
   
End Function
 
 
 Function BytesToBstr(ByVal body As String, ByVal strEncode As String) As String
    BytesToBstr = ""
On Error GoTo error1:
    Dim objstream As ADODB.Stream
    Set objstream = New ADODB.Stream
    objstream.Type = adTypeText
    objstream.Mode = adModeReadWrite
    objstream.open
    objstream.WriteText body
    objstream.Position = 0
    objstream.Type = adTypeText
    objstream.Charset = strEncode      '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码
    BytesToBstr = objstream.ReadText
    objstream.Close
    Set objstream = Nothing
    Exit Function
error1:
   
End Function
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值