如何为所有类型的URL(无论是HTTPS还是HTTP或WWW)创建Web请求并获取其html作为响应?

时间:2019-05-30 18:39:36

标签: c# .net web-scraping system.net

我必须输入www.xyz.ki.com类型的URL的html内容

> I tried this code

using System;
using System.IO;
using System.Net;
class program{
static void Main(string[] args)
{
    List<string> paths = new List<string>() 
      {"https://www.sbi.co.in/careers/ongoing-recruitment.html",
      "www.csd.bih.nic.in/Notification.htm"};
    foreach (var links in paths)
    {
        System.Console.WriteLine("..operating on   :  {0}",links);
        WebRequest request = WebRequest.Create(links);
    WebResponse response = request.GetResponse();
    Stream dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();
    System.Console.WriteLine(responseFromServer);
    }

  }
}

它仅对第一个URL有效,但是当控制权传递给第二个URL时,它会给出错误

  

“ System.UriFormatException:无效的URI:无法确定URI的格式。

0 个答案:

没有答案