Dim web As New System.Windows.Forms.WebBrowser() web.Navigate("http://ip.qq.com/") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim elems As System.Windows.Forms.HtmlElementCollection Elems = web.Document.GetElementsByTagName("Body") '根据标签得到数据集合 Dim data As String = elems(0).InnerText Dim start As Integer = data.IndexOf("IP为") + 4 Dim ip91 As String =trim(data.SubString(start,15)) 'IP地址,最多15个字符 Dim i As Integer Dim j As String For i =8 To 15 'IP地址至少7位 j =mid(ip91,i,1) If j=chr(10) Then ip91=mid(ip91,1,i-1) '最终的IP地址 Exit For End If Next start = data.IndexOf("IP所在地为") + 9 Dim ip92 As String=trim(data.SubString(start,15)) 'IP地址对应的城市,最多15个字符 For i =6 To 15 '城市最少5个字符 j =mid(ip92,i,1) If j=" " Then ip92=mid(ip92,1,i-1) '最终的城市,忽略后面的运营商 Exit For End If Next ip91=ip91 & "|" & ip92 '合并 msgbox(ip91) 'End If
|