欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 利用代理爬虫网页的实现方法

程序员文章站 2023-12-13 10:31:16
c# 利用代理爬虫网页 实现代码: // yanggang@mimvp.com // http://proxy.mimvp.com // 2015-11-0...

c# 利用代理爬虫网页

实现代码:

// yanggang@mimvp.com
// http://proxy.mimvp.com
// 2015-11-09
 
using system;
using system.io;
using system.net;
using system.text;
 
namespace consoleapplication1
{
  class program
  {
    public static void main(string[] args)
    {
      system.net.webproxy proxy = new webproxy("218.21.230.156", 443);    // "107.150.96.188", 8080
      httpwebrequest request = (httpwebrequest)webrequest.create("http://proxy.mimvp.com");
      request.proxy = proxy;
      using (webresponse response = request.getresponse())
      {
        using (textreader reader = new streamreader(response.getresponsestream()))
        {
          string line;
          while ((line = reader.readline()) != null)
            console.writeline(line);
        }
      }
    }
 
    public static void main2()
    {
      // your code goes here
      system.net.webproxy proxy = new webproxy("107.150.96.188", 8080);
      system.net.httpwebrequest req = (httpwebrequest)webrequest.create("http://www.baidu.com");
      req.proxy = proxy;
      req.timeout = 30 * 1000;
      system.net.httpwebresponse resp = (httpwebresponse)req.getresponse();
      encoding bin = encoding.getencoding("utf-8");
      streamreader reader = new streamreader(resp.getresponsestream(), bin);
      string str = reader.readtoend();
      console.writeline(str);
     
      reader.close();
      reader.dispose();
    }
  }
}

获取更多代理,请访问米扑代理:

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:

下一篇: