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
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西