我在尝试获取一些元素并返回字符串时遇到了很大的麻烦。 我有一些试图获得字符串的例子,但不是很难做到。
HTML Phrasing对我来说很难做到这一点,我们将不胜感激。
解释我需要什么:
我需要在输入IP时从该站点获取不同元素的strinsg http://www.ip-tracker.org/
我需要几乎所有细节,但需要标签或文本框。
或者用xml短语 http://ip-api.com/xml/8.8.8.8
所以这是我到目前为止使用的例子,但是还没有达到目的。
Exmaple 1 :
Dim client As New WebClient
Dim ip As String
Dim city As String
Dim Region As String
Private Function GetIp()
Try
Dim Page As String = client.DownloadString("http://www.ip-tracker.org/locator/ip-lookup.php?ip=82.16.38.43/")
ip = Page.Substring(Page.IndexOf("IP Address:") + 80)
ip = ip.Substring(0, city.IndexOf(" </td") + 30)
TextBox2.Text = ("IP Address: " + ip)
Catch ex As Exception
city = "Unable to lookup"
End Try
Return 0
End Function
要打电话:
getViews()
答案 0 :(得分:0)
试试xml linq
Imports System.Xml
Imports System.Xml.Linq
Module Module1
Dim url As String = "http://ip-api.com/xml/8.8.8.8"
Sub Main()
Dim query As XElement = XElement.Load(url)
Dim status As String = query.Element("status").Value
Dim country As String = query.Element("country").Value
Dim region As String = query.Element("region").Value
Dim regionName As String = query.Element("region").Value
Dim city As String = query.Element("city").Value
Dim zip As String = query.Element("zip").Value
Dim lat As Double = query.Element("lat").Value
Dim lon As Double = query.Element("lon").Value
Dim timezone As String = query.Element("timezone").Value
Dim isp As String = query.Element("isp").Value
Dim org As String = query.Element("org").Value
Dim _as As String = query.Element("as").Value
Dim subQuery As String = query.Element("query").Value
End Sub
End Module