C# 利用代理爬虫网页的实现方法
C#利用代理爬虫网页
实现代码:
//yanggang@mimvp.com
//http://proxy.mimvp.com
//2015-11-09
usingSystem;
usingSystem.IO;
usingSystem.Net;
usingSystem.Text;
namespaceConsoleApplication1
{
classProgram
{
publicstaticvoidMain(string[]args)
{
System.Net.WebProxyproxy=newWebProxy("218.21.230.156",443);//"107.150.96.188",8080
HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create("http://proxy.mimvp.com");
request.Proxy=proxy;
using(WebResponseresponse=request.GetResponse())
{
using(TextReaderreader=newStreamReader(response.GetResponseStream()))
{
stringline;
while((line=reader.ReadLine())!=null)
Console.WriteLine(line);
}
}
}
publicstaticvoidMain2()
{
//yourcodegoeshere
System.Net.WebProxyproxy=newWebProxy("107.150.96.188",8080);
System.Net.HttpWebRequestreq=(HttpWebRequest)WebRequest.Create("http://www.baidu.com");
req.Proxy=proxy;
req.Timeout=30*1000;
System.Net.HttpWebResponseresp=(HttpWebResponse)req.GetResponse();
Encodingbin=Encoding.GetEncoding("UTF-8");
StreamReaderreader=newStreamReader(resp.GetResponseStream(),bin);
stringstr=reader.ReadToEnd();
Console.WriteLine(str);
reader.Close();
reader.Dispose();
}
}
}
获取更多代理,请访问米扑代理:
http://proxy.mimvp.com
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!