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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
9 E$ Y D3 `* d- Q; I5 W
" I3 H9 ~' K# J# m% X( b2 @% W( T$ b
网页采集程序(超级简单版)
' _% c O- X- ^
k7 {/ R8 Z! I# b" J

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

8 G$ u8 R% o g6 o8 a7 r- Q3 }( {& J

02         { 

. J% X7 w3 j: q6 H4 Z2 o1 P: q5 s

03             //方法一: 

' m1 ]/ P' v- k7 [9 Z

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

( D5 K4 q$ b% J1 {( Q

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

. L1 ?5 j7 x( U4 ^: n6 J; T0 N( B

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

* T: |% }: w0 o, o+ P

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

6 M- j+ O: ^; a' [; E! o2 ^+ t

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

$ m0 ?9 r% b2 l

09             //Response.Write(html); 

0 b0 }9 b+ f0 j/ |

10   

- d, ?; {0 X) X9 q# W! u

11             //方法二: 

2 q1 l$ M* U6 l; v) |& A8 N4 a* q

12         //获取整个网页 

& Z- ]+ Z8 L3 B; W- X# x0 Z

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

' X# b; K+ i F

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

, g) S3 p+ s1 A, R* G [6 h

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

8 ^) v! ~2 |0 C

16             string html = sr.ReadToEnd(); 

3 y! h' Y3 \5 j2 f( e; p

17             sr.Close(); 

3 [5 f0 t& i% {8 Y( I) N

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

! P$ s, `6 s' e- ]6 N5 l

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

6 K0 P4 V/ f1 r

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

5 W! ]/ O* S2 J

21             Response.Write(html); 

% }) e# C! U7 M0 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号 )