how to extract values from webpage

  • Thread starter Thread starter shantanu
  • Start date Start date
S

shantanu

Hi all
I have a requirement and i need some resolution to work on.

i have to read a webpage and extract few values from the page. I am
using the httpwebrequest meathod to query the webpage that based on
the values generate a result on the webpage and then i need to pick
the phone number and the email id displayed on the page.

kindly assist how to extract values

regards
shantanu
 
Hello shantanu,

Use the following codesnippet, which returns u the page content into the
string.
Everyting u need to do is to extract the desired info from string

public static string GetHtmlFromUrl(string url)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException("url","Parameter is null or empty");

string html = "";
HttpWebRequest request = GenerateHttpWebRequest(url);
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (VerifyResponse(response) == ResponseCategories.Success)
{
// Get the response stream.
Stream responseStream = response.GetResponseStream();
// Use a stream reader that understands UTF8.
using(StreamReader reader =
new StreamReader(responseStream, Encoding.UTF8))
{
html = reader.ReadToEnd();
}
}
}
return html;
}


---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

s> Hi all
s> I have a requirement and i need some resolution to work on.
s> i have to read a webpage and extract few values from the page. I am
s> using the httpwebrequest meathod to query the webpage that based on
s> the values generate a result on the webpage and then i need to pick
s> the phone number and the email id displayed on the page.
s>
s> kindly assist how to extract values
s>
s> regards
s> shantanu
 
Hello shantanu,

Use the following codesnippet, which returns u the page content into the
string.
Everyting u need to do is to extract the desired info from string

public static string GetHtmlFromUrl(string url)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException("url","Parameter is null or empty");

string html = "";
HttpWebRequest request = GenerateHttpWebRequest(url);
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (VerifyResponse(response) == ResponseCategories.Success)
{
// Get the response stream.
Stream responseStream = response.GetResponseStream();
// Use a stream reader that understands UTF8.
using(StreamReader reader =
new StreamReader(responseStream, Encoding.UTF8))
{
html = reader.ReadToEnd();
}
}
}
return html;
}

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

s> Hi all
s> I have a requirement and i need some resolution to work on.
s> i have to read a webpage and extract few values from the page. I am
s> using the httpwebrequest meathod to query the webpage that based on
s> the values generate a result on the webpage and then i need to pick
s> the phone number and the email id displayed on the page.
s>
s> kindly assist how to extract values
s>
s> regards
s> shantanu

Adding to that, if the data you're looking for is always in a particular
location in the page, you can use regular expressions to extract it
 
Back
Top