vb.net 如何从 URL 中获取 HTML 并将其显示在某个位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13499908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get HTML from the URL and display it in certain place?
提问by Scott
I'm in progress with my first application in visual basic, and I'm using the visual basic studio - My question is, how can I get raw HTML data from specified URL, and then display it in my form on the certain position?
我正在使用visual basic中的第一个应用程序,我正在使用visual basic studio - 我的问题是,如何从指定的URL获取原始HTML数据,然后在我的表单中的某个位置显示它?
I havent tried anything yet, because I havent found much solutions about this on the internet.
我还没有尝试过任何东西,因为我还没有在互联网上找到很多关于这个的解决方案。
回答by Steven Doggart
You need to use the HttpClientclass or the WebClientclass to get the raw HTML as a string. Then, you can simply display the string in any control on your form such as a TextBoxor Labelcontrol.
您需要使用HttpClient类或WebClient类来获取原始 HTML 作为字符串。然后,您可以简单地在表单上的任何控件(例如 aTextBox或Label控件)中显示字符串。
For instance:
例如:
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim client As WebClient = New WebClient()
Label1.Text = client.DownloadString("http://www.stackoverflow.com")
End Sub

