Private Sub Form_Load()' 导航到获取 IP 信息的网站
WebBrowser1.Navigate "http://www.ip138.com/"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
'确保加载的是主框架页面
Dim doc As HTMLDocument
Set doc = WebBrowser1.Document
If Not doc Is Nothing Then
'获取包含 IP 归属地信息的元素
Dim ipElement As IHTMLElement
Set ipElement = doc.getElementById("result")
If Not ipElement Is Nothing Then
'提取 IP 归属地信息
Dim ipInfo As String
ipInfo = ipElement.innerText
'显示 IP 归属地信息
MsgBox ipInfo
End If
End If
End If
End Sub