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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
5 O+ e0 s5 h% l: V1 w
- I( s) F' v; _3 e. V6 b. p
网页采集程序(超级简单版)
/ ]$ @( P( Y' K1 T+ U. p8 x
- E( G, w/ f1 I4 O9 D5 ~

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

% u: S, n7 K: Q4 d# N, Z

02         { 

1 L: t0 ` A* C

03             //方法一: 

3 \7 O# N- m. u6 x

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

. P2 w& c/ A# Z9 \8 u

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

+ Y$ l$ x p8 O8 r' H# ?

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

' A9 l. ~0 A2 ?# U. b" L6 W6 k P

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

$ z8 D$ b: N: }: }9 Q D

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

, L9 G( x. p; T7 ]# R

09             //Response.Write(html); 

7 y! F# N6 `" z' V1 |7 _4 B% V- K; u

10   

3 X0 o, M7 ~# a

11             //方法二: 

7 v5 _7 b, }" \0 M0 F# F

12         //获取整个网页 

2 e' ^# D8 W3 i+ E- y% L9 _

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

5 b; A0 a2 v9 V; G( C B% R

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

* S" c7 C1 Q. x+ a5 q5 f% z4 R5 k6 S

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

7 Z$ s: A1 Z7 P

16             string html = sr.ReadToEnd(); 

6 g* E; @/ A% g8 M

17             sr.Close(); 

- E$ P3 @& K5 o8 o1 o1 L

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

& g' c9 x5 g s' F

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

- Q' }$ _/ j3 _; }8 J* n" E

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

; x" u, G" n/ I6 @ S# e; O

21             Response.Write(html); 

' V- {* m6 c/ c* L/ 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号 )