一个简单的优酷视频链接探测与分享功能
这里只是一个展示,实际可以使用Ajax方式调用。另外还可以加入短网址功能毕竟这种视频地址一般不短。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
链接地址:<asp:TextBox ID="TextBox1" runat="server" Height="32px"
Width="438px"></asp:TextBox><br />
页面标题:<asp:TextBox ID="TextBox3" runat="server" Height="32px"
Width="438px"></asp:TextBox><br />
视频代码:<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"
Height="173px" Width="439px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><br />
耗时:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
<div id="div" runat="server"></div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
链接地址:<asp:TextBox ID="TextBox1" runat="server" Height="32px"
Width="438px"></asp:TextBox><br />
页面标题:<asp:TextBox ID="TextBox3" runat="server" Height="32px"
Width="438px"></asp:TextBox><br />
视频代码:<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"
Height="173px" Width="439px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><br />
耗时:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
<div id="div" runat="server"></div>
</form>
</body>
</html>
C#代码using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Net;
using HtmlAgilityPack;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
var time1 = DateTime.Now;
WebRequest request1 = WebRequest.Create(TextBox1.Text);
var str = request1.GetResponse().GetResponseStream();
var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(str,true);
var nodes = doc.DocumentNode.SelectSingleNode("//title");
TextBox3.Text = nodes.InnerText;
var flv = doc.GetElementbyId("link3");
TextBox2.Text = flv.Attributes["value"].Value;
div.InnerHtml = TextBox2.Text;
Label1.Text = (DateTime.Now - time1).TotalMilliseconds.ToString();
}
}
using System.Text;
using System.Web;
using System.Web.UI;
using System.Net;
using HtmlAgilityPack;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
var time1 = DateTime.Now;
WebRequest request1 = WebRequest.Create(TextBox1.Text);
var str = request1.GetResponse().GetResponseStream();
var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(str,true);
var nodes = doc.DocumentNode.SelectSingleNode("//title");
TextBox3.Text = nodes.InnerText;
var flv = doc.GetElementbyId("link3");
TextBox2.Text = flv.Attributes["value"].Value;
div.InnerHtml = TextBox2.Text;
Label1.Text = (DateTime.Now - time1).TotalMilliseconds.ToString();
}
}