VB.net从html元素获取文本/字符串 [英] VB.net Get text/string from html element

查看:737
本文介绍了VB.net从html元素获取文本/字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试获取一些元素并返回字符串时遇到了很大的麻烦。
我有几个试图获取字符串的例子,但是没有成功。

I'm having major trouble trying to get bits of elements and returning the strings. I have a few exmaples of trying to get the strings and what not but failing hard.

HTML表达式对我来说很难实现,所以我将不胜感激。

HTML Phrasing is difficult for me to do so help would be appreciated.

我需要的解释

我需要取得输入IP
时,此网站上有不同的元素 http://www.ip-tracker.org/

I need to get the strinsg of different elements off this site when entering a IP http://www.ip-tracker.org/

我需要几乎所有的细节,但需要标签或文本框。

I need pretty much all the details but into labels or text boxes.

或者这个xml短语
http://ip-api.com/xml/8.8.8.8

所以这是我到目前为止使用的例子,但还没有达到目的。

So here is the exmaple that i've used so far but haven't got far with it.

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



To call it:

getViews()


推荐答案

尝试xml linq

Try 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

这篇关于VB.net从html元素获取文本/字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆