【问题标题】:How do I get HTML of Google Chrome URL?如何获取 Google Chrome URL 的 HTML?
【发布时间】:2015-11-03 17:08:17
【问题描述】:

我正在使用 Visual Studio 在 Basic 中创建一个项目,该项目必须启动 Google Chrome,导航到“google.com”之类的站点,然后将该站点的源 (HTML) 获取到变量。我怎样才能做到这一点? 其实我是从

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

但我坚持获取网站的 HTML。 有什么帮助吗? (请不要告诉我创建 webbrowser 控件,我需要从 Google Chrome 而不是通过 webbrowser 获取 HTML)

【问题讨论】:

    标签: html .net vb.net process get


    【解决方案1】:

    您不需要网络浏览器控件或启动过程。试试这个:

    Imports System.Net
    

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

    【讨论】:

      【解决方案2】:

      以下代码将为您提供帮助。它在 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 法律处于灰色地带。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-23
        • 2021-08-02
        • 2015-12-04
        • 1970-01-01
        • 1970-01-01
        • 2013-09-29
        相关资源
        最近更新 更多