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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
! Q4 i9 W1 O8 V
4 S. }% z+ }; m0 _3 q& g
网页采集程序(超级简单版)
1 _% y* n; _3 R! W' J2 ~7 l5 m
& v) s4 n' L$ G1 S' G) ~

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

* r* O8 d3 k- W4 n+ ~

02         { 

; r) _; D" ^! t7 g8 y

03             //方法一: 

* I/ N4 L4 q3 W! X" W8 d& s; U }

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

9 m4 ], l4 L/ k9 |& u; u$ P

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

# Z& R: O. k9 O1 q+ J

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

/ |6 `4 d. E7 G* }4 r# A1 H

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

6 T" d4 Y1 m7 S# }9 I2 F

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

1 l; G; S$ ~8 e7 F" n) n/ J

09             //Response.Write(html); 

+ F8 v0 `+ p% k+ M3 C% N$ `

10   

. w% m7 D1 T; I0 d6 i

11             //方法二: 

3 g5 `3 s& ~) X: q* Z( k2 a% j; h

12         //获取整个网页 

W0 h& r. n8 }

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

; }* I! x/ ~1 Y4 s: g: T

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

5 C1 C% a9 Q! g0 @( a- K

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

& E1 K/ m. U" V; @) |

16             string html = sr.ReadToEnd(); 

4 T5 n5 \- M" s7 X

17             sr.Close(); 

* i" k4 W/ k/ c, X \

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

7 o' l' p) f9 C% @% O5 _* I

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

: r# }, l c7 _$ m6 j) V- j

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

0 ^# ?5 z/ A: \% o7 @

21             Response.Write(html); 

/ y1 J x& } J/ }% t) E

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