HI,


would it be possible to print only the TEXT forcast of this website into a textbox....no pictures no nothing just the text. if so how?

Recommended Answers

All 21 Replies

copy and paste into notepad? ;)

ha ha.... come on now. i want to do it via C#. so any SERIOUS ideas?

I was just kidding because I'm not 100% sure what you meant. You want your program to pull data from a webpage and print it out, is that right?

I was just kidding because I'm not 100% sure what you meant. You want your program to pull data from a webpage and print it out, is that right?

Lol yea i knew you were kidding. ok this is what i want it to do. Just in the link above in earlier post as you can see there is 36 hrs worth of forcast right there in text. I want to open that info into a text box. (juast text no pics) thats as clear as i can get.Possible?

and you want to do this from a windows app right? I will see what I can figure out on monday.

and you want to do this from a windows app right? I will see what I can figure out on monday.

ok, thanks alot and yes a windows app.

possible but prly not the best way to add weather to an app. i would suggest retreiveing an rss feed from a site like http://www.rssweather.com .

because to get weather from that site yo would need to sent a WebRequest for that website then parse the html for the entire page, and remove all the extra html tags. making extra work thats not needed, but i will include source on a htmlGet and htmlPost so you have an idea on how to do this anyways

this code gets the html from a site

using System.Net;


		private string GetHTML(string strURL)
		{
			WebResponse objResponse = null;
			String strHTML;

			try
			{
				Uri objUri = new Uri(strURL);
				WebRequest objRequest = WebRequest.Create(objUri);
				
				objResponse = objRequest.GetResponse();				
				Stream objStream = objResponse.GetResponseStream();;

				Encoding encode = System.Text.Encoding.UTF8;
				StreamReader objReader = new StreamReader(objStream, encode);

				strHTML = objReader.ReadToEnd();

			}
			catch(Exception ex) 
			{
				return ex.ToString();

			}
			finally 
			{	
				objResponse.Close();

			}

			return strHTML;

		}

		private string Post(string strURL, string strPostData)
		{
			WebResponse objResponse = null;
			string strResult = null;

			try
			{
				Uri objUri = new Uri(strURL);
				WebRequest objRequest = WebRequest.Create(objUri);

				objRequest.Method = "POST";
				objRequest.ContentType = "application/x-www-form-urlencoded";

				StringBuilder UrlEncoded = new StringBuilder();
				Char[] reserved = {'?', '=', '&'};
				Byte[] SomeBytes = null;

				if(strPostData != null)
				{
					int i = 0, j;
					while(i< strPostData.Length)
					{
						j = strPostData.IndexOfAny(reserved, i);
						if(j == -1)
						{
							UrlEncoded.Append(HttpUtility.UrlEncode(strPostData.Substring(i, strPostData.Length - i)));
							break;
						}
						UrlEncoded.Append(HttpUtility.UrlEncode(strPostData.Substring(i, j-i)));
						UrlEncoded.Append(HttpUtility.UrlEncode(strPostData.Substring(j, 1)));
						i = j+1;
						
					}


					SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
					objRequest.ContentLength = SomeBytes.Length;


					Stream objStream = objRequest.GetRequestStream();

					objStream.Write(SomeBytes, 0, SomeBytes.Length);
					objStream.Close();
				}
				else
				{
					objRequest.ContentLength = 0;
				}


				objResponse = objRequest.GetResponse();

				Stream objReceiveStream = objResponse.GetResponseStream();

				Encoding encode = System.Text.Encoding.UTF8;
				StreamReader objReader = new StreamReader(objReceiveStream, encode);

				strResult = objReader.ReadToEnd();

				
				
			}
			catch(Exception ex)
			{
				return ex.ToString();
			}
			finally
			{
				if(objResponse != null)
				{
					objResponse.Close();
				}
			}
			
			return strResult;

		}

possible but prly not the best way to add weather to an app. i would suggest retreiveing an rss feed from a site like http://www.rssweather.com .

because to get weather from that site yo would need to sent a WebRequest for that website then parse the html for the entire page, and remove all the extra html tags. making extra work thats not needed, but i will include source on a htmlGet and htmlPost so you have an idea on how to do this anyways

using System.Net;


		private string GetHTML(string strURL)
		{
			WebResponse objResponse = null;
			String strHTML;

			try
			{
				Uri objUri = new Uri(strURL);
				WebRequest objRequest = WebRequest.Create(objUri);
				
				objResponse = objRequest.GetResponse();				
				Stream objStream = objResponse.GetResponseStream();;

				Encoding encode = System.Text.Encoding.UTF8;
				StreamReader objReader = new StreamReader(objStream, encode);

				strHTML = objReader.ReadToEnd();

			}
			catch(Exception ex) 
			{
				return ex.ToString();

			}
			finally 
			{	
				objResponse.Close();

			}

			return strHTML;

		}

		private string Post(string strURL, string strPostData)
		{
			WebResponse objResponse = null;
			string strResult = null;

			try
			{
				Uri objUri = new Uri(strURL);
				WebRequest objRequest = WebRequest.Create(objUri);

				objRequest.Method = "POST";
				objRequest.ContentType = "application/x-www-form-urlencoded";

				StringBuilder UrlEncoded = new StringBuilder();
				Char[] reserved = {'?', '=', '&'};
				Byte[] SomeBytes = null;

				if(strPostData != null)
				{
					int i = 0, j;
					while(i< strPostData.Length)
					{
						j = strPostData.IndexOfAny(reserved, i);
						if(j == -1)
						{
							UrlEncoded.Append(HttpUtility.UrlEncode(strPostData.Substring(i, strPostData.Length - i)));
							break;
						}
						UrlEncoded.Append(HttpUtility.UrlEncode(strPostData.Substring(i, j-i)));
						UrlEncoded.Append(HttpUtility.UrlEncode(strPostData.Substring(j, 1)));
						i = j+1;
						
					}


					SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
					objRequest.ContentLength = SomeBytes.Length;


					Stream objStream = objRequest.GetRequestStream();

					objStream.Write(SomeBytes, 0, SomeBytes.Length);
					objStream.Close();
				}
				else
				{
					objRequest.ContentLength = 0;
				}


				objResponse = objRequest.GetResponse();

				Stream objReceiveStream = objResponse.GetResponseStream();

				Encoding encode = System.Text.Encoding.UTF8;
				StreamReader objReader = new StreamReader(objReceiveStream, encode);

				strResult = objReader.ReadToEnd();

				
				
			}
			catch(Exception ex)
			{
				return ex.ToString();
			}
			finally
			{
				if(objResponse != null)
				{
					objResponse.Close();
				}
			}
			
			return strResult;

		}

hey thanks man. i thought rss would be the better option. but dont no how to read those. is it easy. Sample code? but thatnks for this im gonna look at it now :)

i dont know yet but thats something i want to learn, so after i learn if you havent figured it out yet i will post some code. post your code when you figure it out to please

will do, thanks for your help.

well i know one way to use rss feed if you know how to work with datasets. its very simple, but i dont know if this is the best way to do this. if someone could suggest a better way i could try.

DataSet ds = new DataSet("RSS Feed");
			ds.ReadXml(@"http://securityfocus.com/rss/news.xml");
			dataGrid1.DataSource = ds;
			dataGrid1.DataMember = "Channel";
			dataGrid1.CaptionText = "RSS Feed";

well i know one way to use rss feed if you know how to work with datasets. its very simple, but i dont know if this is the best way to do this. if someone could suggest a better way i could try.

DataSet ds = new DataSet("RSS Feed");
			ds.ReadXml(@"http://securityfocus.com/rss/news.xml");
			dataGrid1.DataSource = ds;
			dataGrid1.DataMember = "Channel";
			dataGrid1.CaptionText = "RSS Feed";

ok, wait so aan rss feed is an xml file right? if so would be parse that the show just what we want in a text box? thats what i need to do.... is this possile do u know how?

im a bit confused on how this works...i will research rss files....

a rss is only a xml document based on a strict scheme

a rss is only a xml document based on a strict scheme

ok.

have you gotten anywhre with this, i made up a program if you want to see it

sure i would love to see it. i have been able to retrive the headlines. thats about it though havnt really dug in. yea if you wouldnt mind posting it id like to see

http://anti-intelligence.com/files/rssReader.zip

i made this up sorta quick so i hope you understand it

but i displayed it in both a treeview and datagrid

the only problem is googles rss displays html in part of the rss so its hard to read without removing the html

Nice. Yea i understand it. I want to extend it so it gets the whole article. then can save that to a text file. Looks good thx for the ex.


EDIT: For some reson it doesnt seem to be reading google correctly.

its because google rss is meant for a webpage so it adds extra html formatting

all the data for an item is in the "item" table

from there you need to look at the columns

the "title" column is the name of the article and the "description" column holds the story for the titled article. then there also can be other columns like "link" which has the link to the source of the article

its because google rss is meant for a webpage so it adds extra html formatting

all the data for an item is in the "item" table

from there you need to look at the columns

the "title" column is the name of the article and the "description" column holds the story for the titled article. then there also can be other columns like "link" which has the link to the source of the article

yera that makes sense. That wether part is cool. Must figure out how to put the "forcast" into a textbox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.