这篇文章主要介绍了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();
}
}
}
获取更多代理,请访问米扑代理:
http://proxy.mimvp.com
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
沃梦达教程
本文标题为:C# 利用代理爬虫网页的实现方法
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
猜你喜欢
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- Oracle中for循环的使用方法 2023-07-04
- Unity3D实现渐变颜色效果 2023-01-16
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- user32.dll 函数说明小结 2022-12-26
- c# 模拟线性回归的示例 2023-03-14
- .NET CORE DI 依赖注入 2023-09-27
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- Unity Shader实现模糊效果 2023-04-27
- 如何使用C# 捕获进程输出 2023-03-10