关灯
《文稿,还能这样写》作者雄文《笔杆子碎语》作者王一端《机关文稿写作入门》作者杨新宇《机关文字工作五十讲》作者何新国
最新《公文写作培训课程》直播间《公文写作百法例讲》作者房立洲老秘网站长、《老秘笔记》作者老猫《公文高手的自我修养》作者胡森林
开启左侧

网页采集程序(超级简单版)

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
! ~) n% K/ H' o4 W/ Z" V. i7 i
5 i( T% l ?) n# n( d+ h
网页采集程序(超级简单版)
$ b& z7 M9 f9 N/ h3 x& t/ _
; ?% h6 d7 u' m5 f ^

网页采集程序(超级简单版)
01 protected void btn_click(object sender, EventArgs e) 

+ m$ ~# g2 p0 @8 d2 ]

02         { 

& p$ K) [& r0 q

03             //方法一: 

# ]5 y* v" c# F4 W5 N

04             //System.Net.WebClient wc = new System.Net.WebClient(); 

9 X( ]. u) W5 r* n% v2 `! [

05             //byte[] b = wc.DownloadData("http://www.baidu.com"); 

! K" y5 Z4 j }; v0 t0 {; q$ E

06             //string html = System.Text.Encoding.GetEncoding("gb2312").GetString(b); 

5 D# [% @4 {3 I% s! Q

07             //html = html.Substring(html.IndexOf("<p id=\"lg\">") + "<p id=\"lg\">".Length); 

% K3 t7 \* `) @2 \& f! ]- r

08             //html = html.Substring(0, html.IndexOf("</p>")); 

* g- P5 a) g( g; z5 ]: W

09             //Response.Write(html); 

7 i6 \! ?* Y5 A P5 R/ Z2 K+ K

10   

3 M: m( o( U2 g, S' d

11             //方法二: 

7 f) s8 v& l! W+ f) H: }7 V

12         //获取整个网页 

0 {8 Q+ P% v" T+ L) K5 }

13             System.Net.WebClient wc = new System.Net.WebClient(); 

# S- ^4 [, H4 r" o

14             System.IO.Stream sm = wc.OpenRead("http://www.baidu.com"); 

z$ a2 E4 S7 \8 @( G

15             System.IO.StreamReader sr = new System.IO.StreamReader(sm, System.Text.Encoding.Default, true, 256000); 

( i6 @$ P7 s' x1 m; j& y6 E1 c5 n

16             string html = sr.ReadToEnd(); 

7 m) z3 n6 G1 j

17             sr.Close(); 

( f: S: R! R( E' @: |. F

18             //根据规则获取想要的内容 

+ D$ l; k, T2 I4 d: v

19             html = html.Substring(html.IndexOf("<p id=\"lg\">") + "<p id=\"lg\">".Length); 

* {; y/ \+ }: {7 }/ i

20             html = html.Substring(0, html.IndexOf("</p>")); 

) U M4 r% e* k. \/ O" U

21             Response.Write(html); 

2 g ?4 D: U. [) K, y" N

22         }

 

精彩评论1

正序浏览
福建老秘 发表于 2010-7-20 20:00:03 | 显示全部楼层
 
公文写作百法例讲

http://hereson.javaeye.com/blog/207468

 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


0关注

18粉丝

1181帖子

排行榜
作者专栏

关注我们:微信订阅号

官方微信公众号

客服个人微信号

全国服务热线:

0595-22880819

公司地址:泉州秘途文化传媒有限公司

运营中心:福建省泉州市

Email:506070961#qq.com

Copyright   ©2015-2025  老秘网 责任编辑:释然Powered by©Discuz!技术支持:秘途文化  备案号   ( 闽ICP备19022590号-1 闽公网安备35050302000919号 )