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

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

[复制链接]
福建老秘 发表于 2010-7-20 19:53:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
文稿修改演播室众筹计划,点击了解详情
 
W0 a; T4 g/ \! ?) j9 h
# k$ P4 {1 X+ q% S
网页采集程序(超级简单版)
; }( }# ~) p3 Z* [* @% i" {/ }1 H1 u' _
4 m1 [8 J3 P8 W9 [

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

2 H# g. w/ u4 v1 w6 _/ X5 j

02         { 

( _+ U# Z2 H; ~9 y6 j% M

03             //方法一: 

* w2 @, T p3 x! {! ^" R" i

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

2 \+ ^ b/ G& @

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

! w- y5 _% z; P( b" x) k i' {

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

3 _0 V) H1 W" j- `

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

% h% y8 Y, Q9 V& `, Z

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

( t s6 `' ^: \# P( s0 B

09             //Response.Write(html); 

- ? V$ r- _5 S& ~0 e$ ^; R4 B

10   

) g* N' c2 t1 P! S7 A/ l& W. e

11             //方法二: 

: L) c5 K" t! A$ _0 |; ]

12         //获取整个网页 

6 \3 o' ^: x; _

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

! G6 x$ C" Y! c# a2 F

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

/ ^6 ]% @3 j1 `4 Y. y

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

: V1 C) A* O* O8 f. c5 q/ n$ A% y

16             string html = sr.ReadToEnd(); 

+ k D% @# y R* Z5 \

17             sr.Close(); 

9 l5 T1 w& }9 ` T3 o, M

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

! J* G" |/ Y: W. |, M7 f

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

, }* B& L+ n3 F) _1 H

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

5 J1 v" M4 f1 U( T |0 M

21             Response.Write(html); 

. P. P; Q4 q# `4 }5 i" [# G& [

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