[Snippet] RuneScape Price Lookup in C#

A place to discuss development on the Microsoft .NET framework platform utilizing languages such as C#, Visual Basic, J# and Managed C++

Moderators: IRC Operators, Support Team

User avatar
Remy
User
User
Posts: 582
Joined: Sat Jun 03, 2006 8:50 am

[Snippet] RuneScape Price Lookup in C#

Postby Remy » Mon Jun 25, 2007 12:45 am

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

namespace conprice
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the item you wish to search: ");
            string search = Console.ReadLine();
            try
            {
                WebClient price = new WebClient();
                Stream pricestream = price.OpenRead("http://www.zybez.net/priceguide.php?search_terms=" + search + "&search_area=1&price_low=0&price_high=0&member=1&all_prices=1&sortby=name&sort=ASC&ppage=0");
                StreamReader pricereader = new StreamReader(pricestream);
                string read = null;
                string item = null;
                int results = 0;
                while ((read = pricereader.ReadLine()) != null)
                {
                    if (read.StartsWith("<!--price-->"))
                    {
                        Console.WriteLine(item + ": " +  remhtml(read));
                    }
                    if (read.StartsWith("<!--name-->"))
                    {
                        item = remhtml(read);
                        results++;
                    }
                }
                Console.WriteLine("Price lookup complete, " + results + " results found.");
                pricestream.Close();
                Console.Read();
            }
            catch
            {
                Console.WriteLine("An Error Has Occured.");
            }
        }

        public static string remhtml(string html)
        {
            return Regex.Replace(html, "<(.|\n)*?>", "");
        }
    }
}


I'm fairly new to C#, so there may be things I could do to increase efficency, such as, as Rupert stated in his Stats Snippet, removing Regex. Feedback is appreciated. :D

Edit: Zybez changed their source slightly, making my old method no longer work, as it was dependent on reading the next line. I have now made it so it specifically looks for '<!--price-->'.
Last edited by Remy on Thu Jul 05, 2007 12:22 am, edited 1 time in total.
User avatar
Nemo
User
User
Posts: 157
Joined: Sat Jul 22, 2006 1:56 am
Contact:

Postby Nemo » Mon Jun 25, 2007 2:14 am

wuts a class
Image
User avatar
Remy
User
User
Posts: 582
Joined: Sat Jun 03, 2006 8:50 am

Postby Remy » Mon Jun 25, 2007 2:20 am

User avatar
Nemo
User
User
Posts: 157
Joined: Sat Jul 22, 2006 1:56 am
Contact:

Postby Nemo » Mon Jun 25, 2007 2:21 am

Y not C++
Image
User avatar
Remy
User
User
Posts: 582
Joined: Sat Jun 03, 2006 8:50 am

Postby Remy » Mon Jun 25, 2007 2:22 am

Nemo wrote:Y not C++


Why not C#?
Jeff`
User
User
Posts: 78
Joined: Thu Jun 22, 2006 2:21 pm
Location: PALM BEACH

Postby Jeff` » Mon Jun 25, 2007 2:51 am

Thugscape here we come!
gwas hi2u
NoFX
User
User
Posts: 213
Joined: Mon Jul 31, 2006 2:43 am
Contact:

Postby NoFX » Mon Jun 25, 2007 2:53 am

Very nice, Remy
Last edited by NoFX on Fri Jul 11, 2008 12:32 am, edited 1 time in total.
Dayan
Newbie
Newbie
Posts: 13
Joined: Sat Mar 15, 2008 11:21 pm
Contact:

Postby Dayan » Sun Mar 16, 2008 5:00 pm

Kid, you don't need using System.Collections.Generic;
and It doesn't work because there is no <!-Price on the zybez page, they probs removed it.
Other than that, nice.
If I Gt Beef I Ent Runnin, I Raver Stand Here & Put My Hand Wer Ma Gun Iz!
Run Up In Ur Yard Gna Get Ur Door Kicked In,
Nd Im Dayan N I Run In Diz Ting, BANG!
Image

Return to “.NET”

Who is online

Users browsing this forum: No registered users and 1 guest