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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
% j+ n3 u" z3 F" Z9 b9 ?$ @' P4 A
3 z `( ^3 [3 o- s
网页采集程序(超级简单版)
1 L( _/ g5 X8 [0 Y
3 K% @5 P9 V9 [) T& X

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

6 ?' ]# l8 x% }: c8 Z" x7 [

02         { 

* Q! `% s% A7 I. b0 O1 L! J8 Z0 [

03             //方法一: 

! h5 O+ H$ R9 X6 e) K' r& {

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

, `) `' |: e% `2 V8 }! i) p5 o

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

$ ` B5 R, X# ^5 a6 O; G) w

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

2 f! a x8 P( F0 A5 t: L

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

7 e0 V/ K3 r' r/ H1 x, e& O

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

a w" N, F! N. [3 a9 o

09             //Response.Write(html); 

! {7 y1 z& A( `& L* _

10   

/ a, m6 a! {$ q6 p% |

11             //方法二: 

! G; }3 j0 b% C+ ]+ R

12         //获取整个网页 

% a/ ^' E# m2 g

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

0 [5 i7 S& ~" q9 r7 y5 {/ B. `

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

! z- i- P& D( _; G8 D

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

: _* H! s; C& k- u/ T. q( A

16             string html = sr.ReadToEnd(); 

0 F4 z8 x- y8 [8 M4 R/ J

17             sr.Close(); 

% r8 q& Y( `. r# a. M6 p# s ]

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

m: V+ t5 `2 e: r% f% I X- W% I

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

0 B3 F' r6 K, o! i! \; G

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

1 }2 d0 b3 {. K$ G6 G

21             Response.Write(html); 

, H& X9 }+ a _! ^1 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号 )