问题描述
我整整一天都没有什么建议,也没有任何实际进展,试图找到一种方法来正确解析vb.net中的http Web请求.
我已经阅读了教程,但大多数都描述了使用MSHTML的方式,这让我感到困惑.
这是我用来返回所请求网页的HTML的代码:
I have spent all day with little advise and no real progress to try and figure out a way to properly parse a http web request in vb.net.
I have read tutorials but most describe ways to use MSHTML which i find confusing.
This is the code I am using to return the HTML of a requested web page:
Dim input As String = TextBox1.Text
Dim WebAddress As String = "https://www.google.com/" + input
' Create a request for the URL.
Dim request As WebRequest = _
WebRequest.Create(WebAddress)
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Label20.Text = (CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Label2.Text = WebAddress
RichTextBox1.Text = responseFromServer
' Clean up the streams and the response.
reader.Close()
response.Close()
如您所见,Richtextbox1对象充满了HTML输出,但是我只希望在给定的标签或文本框中获取并显示HTML的特定部分.很多人都给出了链接并谈论了HTML Agility Pack,但是我不知道如何在Rich Textbox1中确定HTML输出的区域以实现此目的.
如果有人可以帮助您举一个示例或链接,该示例或链接显示了如何显示从文本框到标签或另一个文本框的选定HTML文本,我将等待您的答复.
在此先谢谢您
As you can see The Richtextbox1 object is filled with the HTML output but I only wish to obtain and show specific portions of the HTML in given labels or textbox. Many people give the link and talk about the HTML Agility Pack but I have no idea how to pin point the areas of the HTML output in my Rich Textbox1 to do this.
Please if anyone can help with an example or a link that shows how to display selected HTML text from a textbox to a label or another textbox I will await your response.
Thank you in advance
推荐答案
这篇关于如何使用敏捷包解析HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!