惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - 鬼手

有趣的网页效果 杀毒软件测试代码 Gmail邀请函 Office的组织结构图 博客园出问题了? 利用js在网页中插入flash JS实现marquee效果 关于IE WebControl 无法加载XML的问题(后续) Ajax.net Onloading Example KBSBBS安装 SQL企业管理器打不开的解决办法 IE WebControl 无法显示XML的问题 自己制作的一些网站 开始要忙了 记录一些网址 备忘 获取地址栏参数 用JAVASCRIPT 控制FRMAE的子窗口 在css中加入事件
获取网页内容
鬼手 · 2006-11-11 · via 博客园 - 鬼手

获取网页的内容,以js方式输出,没有测试性能怎么样。
1.调用页面

<html>
...

<body>
...

<script type="text/javascript" src="GetNews.aspx"></script>
...
</body>
<html>

2.GetNews.aspx,只保留第一行,其它代码不要

<%@ Page language="c#" Codebehind="GetNews.aspx.cs" AutoEventWireup="false" Inherits="PhantomWeb.Components.GetNews" %>

3.GetNews.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;

namespace PhantomWeb.Components
{

/********************************************

  Author:  WebWei
Homepage:  
http://webwei.cnblogs.com/
   Email:  webwei.net@gmail.com   

*******************************************
*/


    
/// <summary>
    
/// GetNews 的摘要说明。
    
/// 获取新闻网最新信息
    
/// 输出JS代码
    
/// </summary>

    public class GetNews : System.Web.UI.Page
    
{
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            GetWebCode();
        }

        
public void GetWebCode()
        
{
            
string url=@"http://news.****.edu.cn/";    //获取输入的网页地址
            string result="";

            
try
            
{
                WebClient wb
=new WebClient();  //创建一个WebClient实例
                
//获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。(可有可无)
                
//wb.Credentials=CredentialCache.DefaultCredentials; 
                
//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
                byte[] pagedata=wb.DownloadData(@url);
                
//转换字符、

                result
=RebulidNews(Encoding.Default.GetString(pagedata));
            }

            
catch(Exception ex)
            
{
                result
=ex.Message;
            }

            Response.Write(result);
//输出JS代码
            
        
        }


        
public string RebulidNews(string pagedata)
        
{
            
string result=@"document.writeln(""<table>"");";
            Regex re 
= new Regex(@"<a href=""http://news.****.edu.cn/(?<id>.*?)""[^>]*target=""_blank"" class=""a2"">(?<text>.*?)</a>(?<date>.*?)</td>", RegexOptions.IgnoreCase);

            
int i=0;
            
for(Match m=re.Match(pagedata);m.Success&&i<10;m=m.NextMatch()) 
            
{
                
                result
+=@"document.writeln(""<tr><td>·<a href=\""http://news.****.edu.cn/";
                result
+=@m.Groups["id"].Value.Trim();
                result
+=@"\"" target=\""_blank\"">";
                result
+=@m.Groups["text"].Value.Trim().Replace(" color='#6495ED'>",">").Replace(" size=2>",">");
                result
+=@"</a><font color='#727272'>";
                result
+=@m.Groups["date"].Value.Trim();
                result
+=@"</font></td></tr>"");";
                i
++;
                
            }

            result
+=@"document.writeln(""</table>"");";
            
return result;

        }


        
Web 窗体设计器生成的代码
    }

}