爬虫意外产物之博客轰炸机
这个程序是前两天写爬虫时的一个小意外,虽然程序很简单,但有时候就是那个想法很关键。
我们知道博客的浏览量的计算是按次计算的,而且这个浏览量是只要访问一次这个页面就增加1。
那么想法就是使用循环,多次访问这个页面即可达到目的。
代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Threading;
namespace 博客访问量 {
class Program {
/// < summary>
/// 用try catch,然后写continue的话,这个程序不跑完绝对不会停止,如果出现异常,就继续尝试,这样正和我意
/// good job O(∩_∩)O哈哈~
/// < /summary>
///
static void Main(string[] args) {
System.Net.WebClient client = new WebClient();
for (int i = 0; i < 10000; i++) {
try {
Stream strm = client.OpenRead("http://blog.csdn.net/jtahstu/article/details/47411757");
strm.Close();
Console.WriteLine("目前正在执行第{0}次轰炸", i);
} catch (Exception e) {
Console.WriteLine(e.Message);
continue;
}
}
}
}
}
实际代码就一行,然后就是处理异常的问题了。
这个方法如果想延伸至QQ空间的话就没用了,QQ空间的访问量是按访问的qq账号计算的,显然这个方法就行不通了,也就拿来玩玩博客了,过两天去学校本人来跑个三天三夜,O(∩_∩)O哈哈~
