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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
. f/ Y, E- O2 f" `
, W1 B/ L3 C/ ?8 k8 K- K3 n, A. q
网页采集程序(超级简单版)
r, P9 z5 b" c4 Y
8 U" m' e0 D7 @1 ]

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

" {, o0 F/ a4 j* r1 B

02         { 

4 I) |. x5 v" N/ J W

03             //方法一: 

9 x6 y' d# Q" B" p% ~4 f

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

$ `1 D; C$ M8 s3 |7 p

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

$ S; v* r7 i( C& k

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

o" z# r; s) p& K

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

5 ^2 M' c: d( k# e

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

) v/ C$ l( W7 g* `& M

09             //Response.Write(html); 

. E5 ~4 q+ [0 z! d( z; n

10   

8 s" I4 n: v9 i `% c

11             //方法二: 

/ J5 `. d- G$ v" _8 u) Q1 H

12         //获取整个网页 

" \& S7 f# n% U1 f, P

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

7 c/ V; X0 B- e. @

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

9 [1 y2 a) z5 Z, m# E

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

) Y: v; @3 F% ~$ k% |3 P

16             string html = sr.ReadToEnd(); 

! I' p" D/ D, F' A/ K6 d' ?: o O9 s

17             sr.Close(); 

) `' n: t2 t* j0 X# S* _6 m

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

& K* W- j% h4 @/ S* w0 V! F3 F0 @: v

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

$ [0 L& ]5 v& [8 i0 M; P; E

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

+ N! |6 M, d. D8 y

21             Response.Write(html); 

, Y9 h% d! K; N1 B' @5 u

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