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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
7 d& d2 L4 T& k
" b* ~) o, t% H6 q9 I( \
网页采集程序(超级简单版)
% W- C% a, S9 Z5 B+ R( b
( P2 \* {" e0 v' }4 X

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

4 Z6 ]8 _) `& v( x6 r

02         { 

3 h9 i7 P1 U2 O5 G, c6 W. c

03             //方法一: 

( k& M* h( Z# _, e/ j/ r* W

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

X; y' ?: z7 x. h8 J

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

0 M0 n8 R m+ L- @% _

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

9 U! t N8 }+ j" i+ R0 @

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

& d6 a0 x9 S6 p6 x; R6 K, y

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

% ~3 A, a' `6 v( w, o% k0 C' }

09             //Response.Write(html); 

) M. O' g+ m; V3 y- U$ m I

10   

9 i! o. t1 w: H3 |- L0 {2 F) c

11             //方法二: 

! E0 E' c0 Z# \) E) w

12         //获取整个网页 

% ], t! @( ]% S. k' l

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

. H& @$ z! H' I7 e

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

' r2 ]* b0 L# P" `

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

1 {) D0 r- P! @0 s+ T3 ?

16             string html = sr.ReadToEnd(); 

; K- Q3 U7 `- ~; b$ B) `* x

17             sr.Close(); 

" Y+ e7 c9 s9 p) w# B

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

) j+ T( ]' q; P* @" R) U

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

* ` B$ t1 ~. b( q( J2 W* _8 o$ A

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

7 S* x# K* Y, P3 f, V( d8 d; }( h

21             Response.Write(html); 

" ^+ h2 B2 I3 {

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