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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
/ k }: j& y0 \3 {/ E1 f" F& m
. ^- _# g; L0 t, Y5 R
网页采集程序(超级简单版)
$ u- S' d- i; k$ v2 {) v" h
* h5 P& A+ ]3 G3 N2 j

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

0 _" e. ~; P3 e1 g& i

02         { 

7 z# H6 A9 @* T3 z3 `' P' n

03             //方法一: 

5 E; D! D% e% r8 |* h' T3 g! i$ t

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

0 y3 m! O4 ?! D5 A, S/ y2 \) q" t

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

{6 a2 Z! e& x

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

# J3 \2 P2 D/ x

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

) n: f; c# N ~; D8 e

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

/ k. Y' u' d5 W9 C

09             //Response.Write(html); 

8 r; Q! q4 v2 D% `8 O0 }

10   

. y( S( A9 A* B/ W; w( n2 h4 `- P

11             //方法二: 

k! \* L# Q$ V

12         //获取整个网页 

1 i1 B e3 ~: c* W$ v0 S. n; G

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

* n( m# S* R: h3 b% s; l0 T7 D

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

& m7 e. `/ u& \- p; X4 V! p7 Z) b/ l

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

- i7 S5 A6 w! ]& C1 G6 r8 J

16             string html = sr.ReadToEnd(); 

& G/ D h5 Y# ^) h% D8 u6 O. Y

17             sr.Close(); 

; {" r; J2 G8 ~( [

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

* T$ [' H& l/ G

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

) Y0 x/ C: p3 m+ x+ M

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

7 |& i8 x; F& }2 G, u% J

21             Response.Write(html); 

3 [( O5 ^2 l { x1 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号 )