ie webpage

  • Thread starter Thread starter RobcPettit
  • Start date Start date
R

RobcPettit

Hi, When using IE you can view the source for the the web page. Is
there a way to use this in c#. What I meen is I can diplay the page
ok, now I want to take the source for that page and run it through
streamreader to get certain values. I know I can use webrequest to do
this, but the particular page I want to do this to will not give all
the details unless displayed in IE. I think its because when the page
is requested it checks for a cookie for certain details, which I dont
know how to get around. The page acts like a basket, which you fill
before using, whence the cookie.
Regards Robert
 
Well, depending on the exact scenario, automating WebBrowser from a
winform might be a simple option? This is essentially IE (well,
"shdocvw") in a .NET-friendly wrapper.

Alternatively, you could learn all the pain of cookies, headers, etc
(perhaps via "fiddler") and do it manually (perhaps with WebClient) -
but I generally only use this approach for simple "REST"-style
requests.

WebBrowser would be my first choice; both for familiarity, and because
it *is* IE (well, the engine).

Marc
 
Thanks for your reply. Ive done as suggested, can you recommend any
were that I can read up on how to grab the source, programatically. I
see I have all the normal internet functions, eg right clicking, so I
guess I work along these lines.
Regards Robert
 
WebBrowser provides full access to the DOM via the Document, or raw
access via DocumentText etc. You can also invoke methods on the HTML
elements (change input values, submit forms, etc) - everything you
might need:

using System;
using System.Windows.Forms;
using System.Diagnostics;
class Demo : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Demo());
}
WebBrowser browser;
public Demo()
{
browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
Controls.Add(browser);
browser.DocumentCompleted += browser_DocumentCompleted;
}

void browser_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
Text = browser.Document.Title;
Trace.WriteLine(browser.DocumentText);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
browser.Navigate(@"http://www.google.com");
}
}
 
Now that is just what I need. Thanks for taking the time to post this.
Its turned out easier than I thought. Much appreciated.
Regard Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top