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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
. A$ l, k. H7 D9 V
7 s) f4 V# @1 k* q
网页采集程序(超级简单版)
& y; K- n" _4 R+ x& j l
. k0 R) Z3 S: k. V5 V: n( c

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

I( T6 f5 Q) e( ^7 y7 F* L7 t+ J" b4 p

02         { 

* [3 f) t# y/ m% \. L

03             //方法一: 

: L( O! ^3 H G0 t* H( Z0 x

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

* ]( i# y7 k$ U& O

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

% V) E/ s$ p( M. j

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

. V0 q" { G& ~- x

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

' C6 r7 q+ o4 O- |+ m

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

% |( h% {) K2 u0 h

09             //Response.Write(html); 

- ^5 D# q9 L* Q6 w

10   

6 Y- ?# x' |( |& Z1 N! |' S% C

11             //方法二: 

" r O, D9 R$ p/ P' S* R

12         //获取整个网页 

0 r, a' |4 B" Q. v, Q

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

6 V/ M( A U& f# U7 Q

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

: U7 ?/ b! i( D/ M

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

6 E: A( `0 k& g" ]# d

16             string html = sr.ReadToEnd(); 

9 w$ J6 U" F5 w% Y

17             sr.Close(); 

& a- v1 h0 }. y! I# l7 u- f4 }

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

$ N& u( J8 E8 I" V- Z4 V

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

) H& j, \5 K3 m# l5 m

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

$ l/ j: n! j+ y# \

21             Response.Write(html); 

/ @! r y/ |& e \: G5 V9 ?5 J( ^

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号 )