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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
& q. H8 ^3 B1 T0 I0 ?
* l. s# K; B5 T- H7 V% H3 q: G
网页采集程序(超级简单版)
* k; d9 J5 I! F/ _2 V
4 ?. m) X9 z. q( B# ~ [ L* a

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

" @) j, @6 X; h c- d+ }

02         { 

" l! j/ ]3 g1 O) @

03             //方法一: 

1 M* D2 ^! q$ Q! N, M( P

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

( \+ h/ Y6 \, Z) J: p- a4 {" ^

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

. K S( u6 S8 t; u8 W& D( Y i

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

3 u; A% E( ~" B

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

. c% g8 f# C) W& P7 j2 j

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

1 g/ u( f. ^7 S# O# w% R

09             //Response.Write(html); 

. f g7 |' i0 i% g( p& C; q# W" J

10   

7 d7 |6 z8 V) p& g$ `( e4 E' B

11             //方法二: 

2 s, `9 [9 r) A

12         //获取整个网页 

: K* w9 x+ d2 _# v3 k0 r4 s- ]4 v

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

0 f( A" X7 J4 H# E* \2 d% E# A+ R

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

" y' | Y; M2 B2 c; E

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

0 q+ b3 m- q2 V T: n% \. H

16             string html = sr.ReadToEnd(); 

9 z7 c; O9 a8 {6 r

17             sr.Close(); 

- f2 M% J. s+ c2 a

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

& G" P3 Y$ T' i

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

/ x1 z6 ?% Z2 `& e

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

1 V0 M: \5 r# Z5 h

21             Response.Write(html); 

' L, x; M- F( e* J# F5 f+ Z

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