这里的想法是允许调用者为循环的每个循环实现AfterHTMLPieceHandler
,我不知道它是否正确,或者它应该是一个insted或delegate事件。老实说,我不知道区别,但这是另一个问题。
//? Should it be static?
public static class PageScan
{
public delegate string AfterHTMLPieceHandler();
public static string GetHTML(string url)
{
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url);
wRequest.Method = "GET";
HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
StreamReader sReader = new StreamReader(wResponse.GetResponseStream());
string html = sReader.ReadToEnd();
sReader.Close();
wResponse.Close();
sReader.Dispose();
return html;
}
public static void GetPiecesOfHtml(string html, string constantHtml)
{
while (html.IndexOf("http://portfoliopad.com/images/") > -1)
{
// it will retrieve a piece of html given the constantHtml and remove from html in order to break the loop in the end
//How Do I hit the event for each time one cycle of the loop ends?
}
}
}