抓取test

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace SD.Web
{
public partial class GetTaoBaoInfo : System.Web.UI.Page
{
string html = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["Name"]))
{

string url = Request.QueryString["Name"];
html = GetHttpData("http://cha.mzyz.com/get/cha/?username="+url);
Regex regex = new Regex(@"<title>(?<value>[\s|\S]*)</title>");
string title = regex.Match(html).Result("$1");
Label1.Text = title;


}
}
public string GetHttpData(string Url)
{
string sException = null;
string sRslt = null;
WebResponse oWebRps = null;
WebRequest oWebRqst = WebRequest.Create(Url);
oWebRqst.Timeout = 50000;
try
{
oWebRps = oWebRqst.GetResponse();
}
catch (WebException e)
{
sException = e.Message.ToString();
//Response.Write(sException);
}
catch (Exception e)
{
sException = e.ToString();
//Response.Write(sException);
}
finally
{
if (oWebRps != null)
{
StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), Encoding.GetEncoding("utf-8"));
sRslt = oStreamRd.ReadToEnd();
oStreamRd.Close();
oWebRps.Close();
}
}
return sRslt;
}
}
}

原文地址:https://www.cnblogs.com/u137578217/p/3470015.html