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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
7 j$ U* E7 E. @
/ k4 Q0 @" B9 j6 e$ L
网页采集程序(超级简单版)
9 r; l& P3 f/ L$ S" E, |1 B
" f, V; j6 L0 O

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

: y# U( I0 d# {, `% A" e

02         { 

+ C1 ~* c# L2 z9 i

03             //方法一: 

4 M2 f& s& S5 H1 w

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

& ^9 s# Z) g2 Z# M Y7 u8 N

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

2 A8 J( Q4 q# `) W+ t. D4 U% G

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

1 s0 ]0 B" G7 q) F/ X

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

8 D4 E5 a' e* d- y: i

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

) {2 T) w3 }/ J

09             //Response.Write(html); 

f5 t& V* F `. l' q( W7 ?

10   

! ]" U7 u% D5 J# q

11             //方法二: 

& k0 T6 r& ~/ A8 \* y

12         //获取整个网页 

' P2 D, l) c% c) N

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

: T/ m1 U- g: X8 g# F

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

7 d. g G, l5 m9 H

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

- A3 |% c2 `; S

16             string html = sr.ReadToEnd(); 

, k3 s7 n& Q# m5 ^$ y3 k. A( g4 }

17             sr.Close(); 

' R: a- a, c o3 l

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

- r: D; L c( ]4 Q+ B

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

, ^$ `: J1 s3 M) _

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

& N/ o3 m0 j0 E g$ L

21             Response.Write(html); 

- d$ g5 G, q& D9 b& |

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