using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.IO;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) {
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
} public static string GetResponse(string url, string postData, string method, string RequestUri)
{
HttpWebRequest request = null;
try
{
request = (HttpWebRequest)WebRequest.Create(url);
}
catch
{
return "";
} if (request == null)
return ""; request.Method = method;
request.Timeout = 300000;
request.KeepAlive = true;
request.AllowAutoRedirect = true;
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 2.0.50727; CIBA)"; request.CookieContainer = new CookieContainer(); try
{
if (RequestUri != null && RequestUri != "")
request.Referer = RequestUri;
else
request.Referer = request.RequestUri.ToString();
}
catch
{
} request.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse webresponse = null;
try
{
if (postData.Length > 0)
{
byte[] loginDataBytes = Encoding.Default.GetBytes(postData);
request.ContentLength = loginDataBytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
stream.Close();
}
webresponse = request.GetResponse() as HttpWebResponse;
if (webresponse != null)
{
StreamReader reader = new StreamReader(webresponse.GetResponseStream(), Encoding.UTF8);
string strHTML = reader.ReadToEnd(); if (reader != null)
reader.Close(); return strHTML;
}
}
catch
{
}
finally
{
if (webresponse != null)
{
webresponse.Close();
webresponse = null;
}
if (request != null)
{
request.Abort();
request = null;
}
} return "";
} private void timer1_Tick(object sender, EventArgs e)
{
string strHTML = GetResponse("http://www.sina.com");
//正则表达式分析HTML代码
}
}
}
JS都成了.
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
myTimer.Interval = 1000;
myTimer.Enabled = true;
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("");
myHttpWebRequest .Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
myHttpWebRequest .UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 2.0.50727; CIBA)";
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
}