Use HttpWebRequest and set the UserAgent property to something your target site likes.
Main Topics
Browse All TopicsHello experts!
I'm trying to scrape this page:
string orginalPull = ScreenScrape("http://www.p
Here is my method:
private static string ScreenScrape(string url) {
WebRequest req = WebRequest.Create(url);
StreamReader stream = new StreamReader(req.GetRespon
System.Text.StringBuilder sb = new System.Text.StringBuilder(
string strLine;
while ((strLine = stream.ReadLine()) != null) {
if (strLine.Length > 0)
sb.Append(strLine);
}
stream.Close();
return sb.ToString();
}
When I try to scrape the page I'm getting an error from the web page I'm trying to scrape:
Unsupported Browser
It appears that you are viewing this page with an unsupported web browser. This website works best with one of the following supported browsers:
Any idea how I can get around this?
Ghost
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
when doing this:
WebRequest req = WebRequest.Create(url);
req.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
StreamReader stream = new StreamReader(req.GetRespon
I get this error:
System.ArgumentException was unhandled by user code
Message="This header must be modified using the appropriate property.\r\nParameter name: name"
Source="System"
ParamName="name"
StackTrace:
at System.Net.WebHeaderCollec
at System.Net.WebHeaderCollec
at WiHCP.ScreenScrape(String url) in d:\Inetpub\wwwroot\WiBot\W
at WiHCP.btnScrap_Click(Objec
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.Page.RaisePo
at System.Web.UI.Page.RaisePo
at System.Web.UI.Page.Process
InnerException:
tried this:
HttpWebRequest req = (HttpWebRequest)HttpWebReq
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
//req.Headers.Add ("user-agent", "");
StreamReader stream = new StreamReader(req.GetRespon
System.Text.StringBuilder sb = new System.Text.StringBuilder(
string strLine;
while ((strLine = stream.ReadLine()) != null) {
if (strLine.Length > 0)
sb.Append(strLine);
}
stream.Close();
return sb.ToString();
I didn't get an error...but I didn't get the page either....
you can access the page:
http://www.postescanada.ca
this is the one I want scraped.
this is what I get:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm
So I guess I need to feed it a cookie :)
can I do that with the request object? also how do I know what to put in the cookie that I give to the page?
ok cool I'm here:
private string ScreenScrape(string url) {
HttpWebRequest req = (HttpWebRequest)HttpWebReq
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
//req.Headers.Add ("user-agent", "");
req.AllowAutoRedirect = true;
foreach (Cookie oCookie in Response.Cookies) {
req.CookieContainer.Add(oC
}
StreamReader stream = new StreamReader(req.GetRespon
System.Text.StringBuilder sb = new System.Text.StringBuilder(
string strLine;
while ((strLine = stream.ReadLine()) != null) {
if (strLine.Length > 0)
sb.Append(strLine);
}
stream.Close();
return sb.ToString();
}
It's still not working...what did I do wrong?
class Program
{
private static readonly CookieContainer Cookies = new CookieContainer();
private static string ScreenScrape(string url)
{
var req = (HttpWebRequest)HttpWebReq
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
req.AllowAutoRedirect = true;
req.CookieContainer = Cookies;
StreamReader stream = new StreamReader(req.GetRespon
var sb = new StringBuilder();
string strLine;
while ((strLine = stream.ReadLine()) != null)
{
if (strLine.Length > 0)
sb.Append(strLine);
}
stream.Close();
return sb.ToString();
}
static void Main(string[] args)
{
string s =
ScreenScrape(
"http://www.postescanada.c
string s2 =
ScreenScrape(
"http://www.postescanada.c
}
}
The first call through sets up the cookie properly ... it gets returned the meta-refresh ... the second call works properly (because the cookie is in the Cookies container when it does the call).
Cheers,
Greg
Hey guys....it turns out this is still not working...
I posted another question...here:
http://www.experts-exchang
Any help would be awesome!
Thanks!
Business Accounts
Answer for Membership
by: gregoryyoungPosted on 2009-04-27 at 10:46:05ID: 24243957
webRequestObject.Headers.A dd ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");