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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
+ J( P( }( F! Z) G1 b: q
" s1 g' @$ M% j. n
网页采集程序(超级简单版)
) w( p3 M/ I! Y
$ r/ O$ t/ m2 P

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

/ _# m6 @" K5 r' ?5 n, g. }

02         { 

9 t1 J/ Z/ _& z- x3 K

03             //方法一: 

" G0 \- @8 B, N+ d3 r7 y

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

# h, k) b* ` R0 a& C; l H) b- t

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

" ^( e( Z$ c( `4 n! Q

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

" G% b7 N% j0 ]8 K

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

. Y/ u/ @! n; T* b; ] l! l

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

# G7 I) {' S" z% {$ H2 M$ |% U

09             //Response.Write(html); 

_7 s& C. }4 c* z) b: Y

10   

- W# O/ c2 t1 P9 }; w# Y: j# G' o

11             //方法二: 

( I/ _: a- u9 A A2 T' e% l

12         //获取整个网页 

2 u" G1 B0 H# V& Z1 l

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

( b! {6 o) O( E- p/ v

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

! z) y1 h& O3 ^" c7 o) [& }

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

9 k9 ]2 O# `9 H' A0 D( V

16             string html = sr.ReadToEnd(); 

6 d9 O8 ?! ?1 e. o( Q( t

17             sr.Close(); 

2 S4 y; ^ r* _3 o% I+ u1 K' [: i

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

3 z5 n! `# @( O; C, h Z Z C

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

# o: e8 L% A" y5 q4 o

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

( X, N3 D0 A: I( t

21             Response.Write(html); 

+ a0 }3 ~; M( [1 C$ a% o

22         }

 

精彩评论1

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

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

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

本版积分规则


0关注

18粉丝

1180帖子

排行榜
作者专栏

关注我们:微信订阅号

官方微信公众号

客服个人微信号

全国服务热线:

0595-22880819

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

运营中心:福建省泉州市

Email:506070961#qq.com

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