获取下载的Google搜索网站的特定链接

时间:2020-10-21 17:36:42

标签: httpclient webclient

我想在C#中执行以下操作:

  1. 在后台加载网站(谷歌搜索网站)
  2. 查看该网站的源代码并获取特定链接

我之前尝试过此操作

  1. 使用WebClient类下载网站的字符串

WebClient client = new WebClient();
string reply = client.DownloadString(url);
client.DownloadFile(gesamter_String, @"C:\neu\localfile.html");
Console.WriteLine(reply);

  1. 使用HTTPClient类下载网站的字符串

string url = hyperlink;
HttpClient client = new HttpClient();

using (HttpResponseMessage response = client.GetAsync(url).Result)
   {
     using (HttpContent content = response.Content)
     {
      string result =content.ReadAsStringAsync().Result;
                    
       Console.WriteLine(result);
     }
  }

但是下载或显示的源代码很小,并且不包含特定的链接。

但是我的链接有效。我已使用以下链接打开了前台链接:System.Diagnostics.Process.Start(url);。这个前台打开的站点包含完整的源代码。

非常感谢。

0 个答案:

没有答案