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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
1 }9 K$ O% _% m1 c
V8 ]1 p4 {! P
网页采集程序(超级简单版)
, K7 e# b* n. s& I0 R# {3 W
& M# i4 E+ @! M6 t: p3 p

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

$ L3 H3 @; X% `' z

02         { 

7 m3 P7 I9 l, T0 v

03             //方法一: 

2 Q1 \5 M- q& A( b% [/ y

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

; u- |' T1 g: T: A3 }7 M

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

, [+ v- |% R# G: b- o) t

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

1 j2 T) r* D6 |4 z2 \% \" n

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

7 v. J. w6 R' Z& } O. \) B" \

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

1 C! }3 `9 f( v* B! f1 h

09             //Response.Write(html); 

- b( Z; X4 s5 z7 G

10   

, u: N- O+ b; M' R3 U. n9 C6 `

11             //方法二: 

) b$ {5 \* U; U2 t

12         //获取整个网页 

M4 e% W2 M& m

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

p* ~2 H/ z' S

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

9 \" J* j5 R8 J8 v3 g6 s/ v, Z2 F

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

0 @7 v9 p/ E9 c8 ]0 U1 _

16             string html = sr.ReadToEnd(); 

9 L! A9 B: X- J" w

17             sr.Close(); 

$ l8 q' w1 h5 L' L( p

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

) n* t* i$ Q3 R4 ^8 I7 W9 [ | u8 M4 e

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

5 J6 R: Q; P& X; V7 q& F6 C

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

: b" |9 `! U8 x; z2 I+ \* c

21             Response.Write(html); 

$ Q0 \1 H- n/ W# K

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