[Visual Basic] 纯文本查看 复制代码 Option Explicit
Private Sub Form_Load()
Debug.Print getphonedata("13800138000")
End Sub
Public Function getphonedata(strphone As String) As String
On Error Resume Next
Dim global_NetworkAddress As Object
Dim targetUrl As String, cardLocal As String, cardType As String, codeZip As String
Dim i As Byte
targetUrl = "http://m.ip138.com/mobile.asp?mobile=" & strphone '//从这里提取外网数据
Set global_NetworkAddress = CreateObject("MSXML2.SERVERXMLHTTP") '//创建xmlHttp对象
With global_NetworkAddress
Do
i = i + 1: Err.Clear '//记录Try的次数,并清空Err信息
.Open "GET", targetUrl, False
.Send
Loop Until i = 4 Or Err.Number = 0 '//如果第一次获取失败,再尝试3次
'//如果获取成功就返回OK,失败返回错误信息
getphonedata = IIf(Err.Number = 0, "OK", Err.Description)
cardLocal = Split(Split(.ResponseText, "卡号归属地</td><td><span>")(1), "</span>")(0)
cardType = Split(Split(.ResponseText, "卡 类 型</td><td><span>")(1), "</span>")(0)
codeZip = Split(Split(.ResponseText, "邮 编</td><td><span>")(1), "</span>")(0)
getphonedata = getphonedata & "," & strphone & "," & _
cardLocal & "," & cardType & "," & codeZip
End With
Set global_NetworkAddress = Nothing '//释放对象
End Function
|