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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
3 C* P0 x) \0 ?
& U- A+ N' W6 U n
网页采集程序(超级简单版)
6 |* [. X+ Z& a* t
& d( d( d- g( U

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

$ g6 I# d; l, H% ]* c ^

02         { 

) I2 l9 @, u0 e( t2 E. k1 m% k$ b: o

03             //方法一: 

3 `5 }2 r' d, r2 o. `1 v3 E

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

- S6 [/ Z; c( D$ E% U8 {

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

8 E' T9 C2 ]4 k( U) B- f# @

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

& |' k" B5 g4 @% S7 u: p! t

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

# E6 m6 g* E( H0 n" c+ p

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

# H2 o4 Y2 e$ G, G9 H

09             //Response.Write(html); 

9 X* j( `, @1 y2 o# H

10   

6 R8 g: [7 `! h4 m: t. ?: B

11             //方法二: 

( ?! d9 z$ {/ p$ F! U, t

12         //获取整个网页 

/ `$ Q/ n4 l7 R! b5 g9 b1 @

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

/ [, n/ ?( N0 t1 U9 |, ^; V0 O |9 `

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

2 g ]4 f# P; l2 F: \* L

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

$ q0 D1 f3 X# O* G' s

16             string html = sr.ReadToEnd(); 

6 _7 t4 \9 k7 C% ?% L% f

17             sr.Close(); 

4 Z/ |8 \9 H4 z

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

7 W) j3 ~# d6 c

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

, d6 `# \3 X! i$ _4 W, H

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

6 F$ l% L& a5 A8 Y% \5 x0 q

21             Response.Write(html); 

1 A2 Q0 m3 Q9 O, h) X. W

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