code for parsing latest rs news in c#

Discussion in 'Programming General' started by slashshot007, Oct 26, 2007.

code for parsing latest rs news in c#
  1. Unread #1 - Oct 26, 2007 at 5:47 PM
  2. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    code for parsing latest rs news in c#

    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;
    		}
     
< Multi-Threading Question | C++ Forms, Buttons and Text >

Users viewing this thread
1 guest


 
 
Adblock breaks this site