惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

博客园 - 东哥

MongoVUE 错误:can't map file memory - mongo requires 64 bit build for larger datasets HTTP Header 属性列表 安装卸载Windows服务,修改windows服务执行路径! SQL 语句嵌套,自己记录下。 基于RBAC的权限设计模型 javascript中getElementsByName的问题 三级连动JS数据库查询代码整理 动态添加WEB控件,点控件获取动态添加的控件 数据库基本----SQL语句大全 使用Ajax时的十个常犯的错误 WEB Service 下实现大数据量的传输 [转]将上传图片打上防伪图片水印并写入数据库 我奋斗了18年不是为了和你一起喝咖啡(转载) [转]社区好友列表利用率越高,社区越失败 很实用的一个图片上传得例子 [转帖]教程:使用WebService进行异步通信 如何用Javascript记录登陆次数 很酷实用的右键弹出菜单(Js+DVML) JavaScript如果文字过长,则将过长的部分变成省略号显示
数据采集程序(网页小偷)点滴心得
东哥 · 2008-05-09 · via 博客园 - 东哥

所谓的数据采集程序也就是网页小偷程序(大家别骂我哦),写完了来这里发点东西,希望大家有何高见共同研究.

1.在下载数据的开始,有些网站是要登录了才能看到相应的数据,这个就需要我们发送登录用户名和密码了,但我是登录了,但他服务器也不是垃圾,在他那里重定向了,共产生了2个SESSION,这第2个SESSION我就不知道如何捕抓.于是我就投机^-^,用软件将SESSION捕抓下来了1个叫Ethereal的软件,用以下代码加入到HTTP请求的头部
WebClient myWebClient = new WebClient();
string sessionkey=textBox78.Text;
     string refererurl=textBox77.Text;
     myWebClient.Headers.Clear();     
     myWebClient.Headers.Add("Cookie",sessionkey);
     myWebClient.Headers.Add("Referer", refererurl);
     myWebClient.Headers.Add("User-agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3");
这样就欺骗了服务器了,哈哈

2.第二部就是代码下载
byte[] myDataBuffer = myWebClient.DownloadData(remoteUri);
 download = Encoding.Default.GetString(myDataBuffer);

3.第3部就是数据的匹配了,我是将流读取到数据里,然后用IndexOf得到2个关键字段的位置,然后用Substring取出来的,我知道这很笨,但用正则表达式难啊(谁会的指点我下),匹配完了得到的字符串我就用以下的函数去掉了HTML代码:
private string StripHTML(string strHtml)
  {
   string [] aryReg ={
          @"<script[^>]*?>.*?</script>",
          @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(file://[""'tbnr]|[^/7])*?/7|/w+)|.{0})|/s)*?(///s*)?>",
          @"([\r\n])[\s]+",
          @"&(quot|#34);",
          @"&(amp|#38);",
          @"&(lt|#60);",
          @"&(gt|#62);",
          @"&(nbsp|#160);",
          @"&(iexcl|#161);",
          @"&(cent|#162);",
          @"&(pound|#163);",
          @"&(copy|#169);",
          @"&#(\d+);",
          @"-->",
          @"<!--.*\n"        
         };

   string [] aryRep = {
           "",
           "",
           "",
           "\"",
           "&",
           "<",
           ">",
           " ",
           "\xa1",//chr(161),
           "\xa2",//chr(162),
           "\xa3",//chr(163),
           "\xa9",//chr(169),
           "",
           "\r\n",
           ""
          };

   string newReg =aryReg[0];
   string strOutput=strHtml;
   for(int i = 0;i<aryReg.Length;i++)
   {
    Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
    strOutput = regex.Replace(strOutput,aryRep[i]);
   
   }

   strOutput.Replace("<","");
   strOutput.Replace(">","");
   strOutput.Replace("\r\n","");

   return strOutput;
  }

4.到了后面就是入库了,这个大家都懂了吧.但是我还有点问题就是,在我写数据的时候,出了EXCEPTION,说我的字段太长了,不能写进到数据库,我用的是ACCESS,我试验下用SQL吧.

5.大家有什么好的建议给我留个言赛.共同进步嘛.