Scraping Description

eminemino

New Member
I am trying to scrape the weather section from the following page http://www.zamnet.zm but am having trouble with my code - can anyone help out?<BR><BR><%@ Import Namespace="System.Net" %><BR><%@ Import Namespace="System.IO" %><BR><script language="C#" runat="server"><BR> void Page_Load(Object Src, EventArgs E) {<BR> myPage.Text = readHtmlPage("http://www.zamnet.zm");<BR> myWeather.Text = GetWeather(myPage.Text, "Lusaka Today","View Other Zambian Cities");<BR> }<BR><BR> private String readHtmlPage(string url)<BR> {<BR> String result;<BR> WebResponse objResponse;<BR> WebRequest objRequest = System.Net.HttpWebRequest.Create(url);<BR> objResponse = objRequest.GetResponse();<BR> using (StreamReader sr = <BR> new StreamReader(objResponse.GetResponseStream()) )<BR> {<BR> result = sr.ReadToEnd();<BR> // Close and clean up the StreamReader<BR> sr.Close();<BR> }<BR> return result;<BR> } <BR><BR><BR> private static string GetWeather(string Content, string beginSection, string endSection) <BR> {<BR> int iFoundBegin = Content.IndexOf(beginSection);<BR> if (iFoundBegin != -1)<BR> {<BR> int iFoundEnd = Content.IndexOf(endSection,iFoundBegin +<BR> beginSection.Length);<BR> <BR> if (iFoundEnd != -1)<BR> {<BR> return Content.Substring(iFoundBegin + beginSection.Length, iFoundEnd -<BR> (iFoundBegin + beginSection.Length));<BR> }<BR> }<BR> <BR> return null;<BR> }<BR><BR></script><BR><html><BR><body><BR><b>This content is being populated from a separate HTTP request to<BR><a href=http://aspmessageboard.com/archive/index.php/"http://www.zamnet.zm">http://www.zamnet.zm</a>:</b><hr/><BR><asp:literal id="myPage" runat="server"/><BR><asp:literal id="myWeather" runat="server"/><BR></body><BR></html><BR><BR>
 
Back
Top