2016-06-01 11 views
-2

要素のビットを取得して文字列を返そうとすると大きな問題を抱えています。 私は文字列を取得しようといくつかのexmaplesを持っていますが、ハードに失敗しないもの。VB.net html要素からテキスト/文字列を取得する

HTMLフレーズは難しいので、助けていただければ幸いです。私はを必要とするものの

Explantion: http://www.ip-tracker.org/

は、私はほとんどすべての詳細が、ラベルやテキストにする必要があるIPアドレスを入力するとき、私はこのサイトオフ異なる要素のstrinsgを取得する必要があります

ボックス。だからここ http://ip-api.com/xml/8.8.8.8

のxmlフレージングと

それともこれは私がこれまで使ってきたが、はるかにそれを持っていないexmapleです。

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

のXML LINQをお試しください。 – SLaks

+0

どのように使用するのexmarples? 、私はここで少し錆びています。 –

+0

GoogleでLINQ to XMLと 'XElement'を検索してください – SLaks

答えて

0

は、あなたがXMLパーサーを使用する必要が

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 
+0

あなたは絶対的な人生!それは魅力のように動作し、うまくいけば、IPトラッカーのxmlバージョンのより多くのタイプがあります! ありがとうございます! –

関連する問題