2015-11-03 137 views
-1

我使用Visual Studio创建基本项目,必须启动Google Chrome浏览器,导航到像“google.com”这样的网站,然后将该网站的源代码(HTML)转换为变量。我怎样才能做到这一点? 其实,我开始如何获取Google Chrome URL的HTML?

Process.Start("chrome.exe", "http:\\google.com") 

但是我坚持让网站的HTML。 有什么帮助吗? (请不要告诉我创建一个webbrowser控件,我需要从谷歌Chrome返回HTML而不是通过网页浏览器)

回答

0

您不需要Web浏览器控件或启动过程。刚刚尝试这一点:

Imports System.Net 

Dim web As New WebClient() 
Dim source As String = web.DownloadString("www.google.com") 
0

下面的代码将帮助你。它在C#中,但VB可以实现完全相同的事情,只有其他语法。

string urlAddress = "http://google.com"; 

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress); 
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 

if (response.StatusCode == HttpStatusCode.OK) 
{ 
using(Stream receiveStream = response.GetResponseStream()) 
{ 
    using(StreamReader readStream = new StreamReader(receiveStream)) 
    { 
    string data = readStream.ReadToEnd(); 
    } 
    }  
} 

附注:我不知道你的要求,我也不想知道,但要知道,这个概念被称为屏幕抓取,这是在灰色地带的IT法律条款。

相关问题