pdpullmn612
November 28th, 2008, 01:41 PM
Hey guys,
I am writing a dictionary program that looks to Meriam Webster for the definition of a word after the user inputs one and then displays it in the console. I was able to access Meriam Webster and strip most of the HTML code. However, I need to rid of anything extra. I want just the dfinition displayed in the console window. Here is my code so far,
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
HttpWebRequest HttpWReq;
string word;
string url;
Stream receiveStream;
StreamReader readStream;
string line;
while (true)
{
Console.WriteLine("Please enter a word:");
word = Console.ReadLine();
url = "http://www.merriam-webster.com/dictionary/" + word;
try
{
HttpWReq = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
receiveStream = HttpWResp.GetResponseStream();
readStream = new StreamReader(receiveStream);
line = readStream.ReadLine();
while (line != null)
{
line = Regex.Replace(line, @"<(.|\n)*?>", string.Empty);
Console.WriteLine(line);
line = readStream.ReadLine();
}
readStream.Close();
HttpWResp.Close();
}
catch (Exception ex)
{
Console.WriteLine("caught exception");
}
}
}
}
}
I noticed in the HTML code that there is a specific set up of the tags before and after the definition. Is there anyway I can just display the information between those HTML tags?
Thanks in advanced guys.
I am writing a dictionary program that looks to Meriam Webster for the definition of a word after the user inputs one and then displays it in the console. I was able to access Meriam Webster and strip most of the HTML code. However, I need to rid of anything extra. I want just the dfinition displayed in the console window. Here is my code so far,
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
HttpWebRequest HttpWReq;
string word;
string url;
Stream receiveStream;
StreamReader readStream;
string line;
while (true)
{
Console.WriteLine("Please enter a word:");
word = Console.ReadLine();
url = "http://www.merriam-webster.com/dictionary/" + word;
try
{
HttpWReq = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
receiveStream = HttpWResp.GetResponseStream();
readStream = new StreamReader(receiveStream);
line = readStream.ReadLine();
while (line != null)
{
line = Regex.Replace(line, @"<(.|\n)*?>", string.Empty);
Console.WriteLine(line);
line = readStream.ReadLine();
}
readStream.Close();
HttpWResp.Close();
}
catch (Exception ex)
{
Console.WriteLine("caught exception");
}
}
}
}
}
I noticed in the HTML code that there is a specific set up of the tags before and after the definition. Is there anyway I can just display the information between those HTML tags?
Thanks in advanced guys.