这篇文章主要为大家展示了“C#如何使用代理爬虫网页的实现方法”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“C#如何使用代理爬虫网页的实现方法”这篇文章吧。
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();
}
}
}
以上是“C#如何使用代理爬虫网页的实现方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注天达云行业资讯频道!