• Log in or sign up for an account here: https://www.sythe.org/login

code for parsing latest rs news in c#

slashshot007

Active Member
Joined
May 6, 2006
Sythe Gold
0
Messages
164
I got my computer taken away for two months, during which i was taking a java course, so when i came back i had plenty of stuff to try.

so i updated my vb code for getting rs news from the main page to c#, and made it a lot cleaner, and smaller.

Code:
		String parselink(int whichone, String html)
		{
			int start = 0;
			for (int i = 1; i <= whichone; i++)
				start = html.IndexOf("0.5em;\"><a href=\"", start) + 17;
			return html.Substring(start, html.IndexOf("\">Read", start) - start);
		}

		String parsetitle(int whichone, String html)
		{
			int start = 0;
			for (int i = 1; i <= whichone; i++)
				start = html.IndexOf("\"newsdate\">", start) + 11;
			String hi = html.Substring(start, html.IndexOf("</d", start) - start);
			return hi.Replace("</span>", ": ");
		}

		String parsebodytext(int whichone, String html)
		{
			int start = 0;
			for (int i = 1; i <= whichone; i++)
				start = html.IndexOf("text-align: justify; vertical-align: top;\">", start) + 43;
			return html.Substring(start, html.IndexOf("</", start) - start);
		}

example form of usage:
Code:
		System.Net.WebClient web = new System.Net.WebClient();
		private void btnrsnews_Click(object sender, EventArgs e)
		{
			String html = web.DownloadString("http://www.runescape.com/title.ws");
			String news = "";
			for (int i = 1; i <= 3; i++)
				news = news + parsetitle(i, html) + "\r\n" + parsebodytext(i, html) + "\r\nFor the full article go here:\r\n" + parselink(i, html) + "\r\n\r\n";
			txtrsnews.Text = news;
		}
 
Runescape Gamblingrunescape gambling
Back
Top