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>
我有这个从一个项目,我做了周围铺设。 它需要的页面和流中读取它变成一个网页浏览器,然后翻出你从它想要的。 我看着面前读一个字符串,问题是对于我来说,至少,你必须找到,标签之间的长度等,这对我来说效果不错:
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
如果你想告诉我的页面,我可以更新的代码,但至少应该帮助回答你的问题。
文章来源: VB.NET - How do I search through Webpage source for particular div and output inside txt as msgbox?