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

所属分类: 软件编程 / C#教程 阅读数: 64
收藏 0 赞 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();
    }
  }
}

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

http://proxy.mimvp.com

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

更多精彩内容其他人还在看

C#使用oledb读取excel表格内容到datatable的方法

这篇文章主要介绍了C#使用oledb读取excel表格内容到datatable的方法,涉及C#操作oledb及datatable的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用oledb操作excel文件的方法

这篇文章主要介绍了C#使用oledb操作excel文件的方法,涉及C#中oledb操作excel的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用IHttpModule接口修改http输出的方法

这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#给图片加水印的简单实现方法

这篇文章主要介绍了C#给图片加水印的简单实现方法,涉及C#操作图片的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#生成随机数的方法小结

这篇文章主要介绍了C#生成随机数的方法,实例总结了C#生成随机数的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#使用jQuery实现无刷新评论提交的方法

这篇文章主要介绍了C#使用jQuery实现无刷新评论提交的方法,涉及C#结合jQuery进行Ajax操作的相关技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#读取中文文件出现乱码的解决方法

这篇文章主要介绍了C#读取中文文件出现乱码的解决方法,涉及C#中文编码的操作技巧,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像对比度调整的方法

这篇文章主要介绍了C#图像对比度调整的方法,涉及C#实现图像对比度操作的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像灰度级拉伸的方法

这篇文章主要介绍了C#图像灰度级拉伸的方法,涉及C#灰度操作的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

C#图像线性变换的方法

这篇文章主要介绍了C#图像线性变换的方法,涉及C#操作图像线性变换的相关技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多