VB.NET-如何在网页源代码中搜索特定的div并在txt中作为msgbox输出?

VB.NET-如何在网页源代码中搜索特定的div并在txt中作为msgbox输出?,vb.net,visual-studio-2010,forms,visual-studio,Vb.net,Visual Studio 2010,Forms,Visual Studio,VB.NET-如何在网页源代码中搜索特定的div并在txt中作为msgbox输出 到目前为止,我可以下载一个网页的源代码。但我不知道如何通过它搜索特定的信息串 迄今为止的代码: Dim source As String = New System.Net.WebClient().DownloadString("http://pagewantingtouse.com") 该部门称为“描述”,我在寻找其中的信息。我想将其输出为消息框 示例如下: <div class="description

VB.NET-如何在网页源代码中搜索特定的div并在txt中作为msgbox输出

到目前为止,我可以下载一个网页的源代码。但我不知道如何通过它搜索特定的信息串

迄今为止的代码:

Dim source As String = New 
System.Net.WebClient().DownloadString("http://pagewantingtouse.com")
该部门称为“描述”,我在寻找其中的信息。我想将其输出为消息框

示例如下:

<div class="description">       
 The Amazing Spider-Man is a 2012 American superhero film based on the Marvel
 Comics character Spider-Man. It is the fourth installment of the Spider-Man film series, serving
 as a reboot.
</div>

《神奇蜘蛛侠》是一部2012年美国超级英雄电影,改编自《奇迹》
漫画人物蜘蛛侠。这是《蜘蛛侠》系列电影的第四部
作为重新启动。

我在做一个项目时就有了这个。它将页面和流读入web浏览器,然后从中提取任何您想要的内容。我以前看过阅读字符串,问题是,至少对我来说,你必须找到标签之间的长度,等等。这对我来说很有效:

 Dim request As WebRequest = WebRequest.Create("http://pagewantingtouse.com") 'create a web request to the html file
    Using response As WebResponse = request.GetResponse() 'get the response back from the request
        Using Reader As New StreamReader(response.GetResponseStream) 'identify how you want to read the response and assign it to streamreader
            Dim webtext As String = Reader.ReadToEnd() 'read the response (web page) as a string to the end of the file

 Dim wbc As WebBrowser = New WebBrowser() 'create a web browser to handle the data. this will help sift through it

            wbc.DocumentText = ""

            With wbc.Document
                .OpenNew(True)
                .Write(webtext) 'write the web page response into the web browser control


                Dim itemlist As HtmlElementCollection = .GetElementsByTagName("DIV")

                    For Each item In itemlist 'look at each item in the collection
                    If item.classname = "description" Then 
                        msgbox item.innertext 'this would msgbox your description
                    Exit For 'exit once found
                    End If



                Next 'do this for every item in the collection until we find it

            End With 

        wbc.dispose()

        End Using

    End Using 

如果您想告诉我页面,我可以更新代码,但这至少有助于回答您的问题。

将循环编辑为if-THEN.classname而不是.class。但是,当同时使用webrequest和webclient.download获取页面字符串时,该网页似乎根本没有返回描述,因为存在浏览器检测方案,并且它表示浏览器不受支持。也许有人能解释一下这个解决方法。我想到的可能是分离出检测并停止浏览器的javascript。