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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
+ j' @0 t+ A$ F
0 C& W9 L ^0 f! T; O: C( t0 M
网页采集程序(超级简单版)
4 R. E2 l7 i3 f q
# e$ e: ]" c& x- }4 i

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

* e5 o8 p& Y+ w# J: A

02         { 

, N" `5 `. i) F% x

03             //方法一: 

. C$ V, g) a, ]4 T! K/ H

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

/ Y8 e7 y. [9 {) ^

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

6 n$ v4 a6 s8 x6 g8 p$ {

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

# l; n' {0 ~' o$ U1 w0 e

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

# g# H6 k3 Z! c! r9 |/ H

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

; S% A4 p, Y2 p; ?

09             //Response.Write(html); 

) D1 E. p3 J8 Z* U5 X' L+ g

10   

! g' s/ d. J$ b

11             //方法二: 

' J8 b# N/ V k2 _

12         //获取整个网页 

$ q( ^9 w# q2 s+ O

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

6 G: i" u+ I, I

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

$ k+ B+ h$ P: L; g: z1 v

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

" c" Y/ ?. y, e0 A5 v

16             string html = sr.ReadToEnd(); 

; H, d7 E$ }1 _

17             sr.Close(); 

7 x+ h% U6 P8 O& O2 A( W

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

+ B, o( H2 W9 K: E4 U; m2 H. j- z4 v0 h

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

% ~- s1 D; e- h- P7 Z8 O2 p2 b

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

# t6 J' D5 A2 [, D1 T" r( R( T1 @

21             Response.Write(html); 

# J. W* O/ H9 S4 B- V2 ~. C

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