Accessing the javascript on a webpage using Webrequest/Webresponse

G

gizmo

Hi,

I'm using the following code to request the html source from the
quoted site.

......
string url = "http://www1.soccerstand.com/";
WebRequest webRequest = WebRequest.Create(url);
WebResponse webResponse = webRequest.GetResponse();
beginStr = new StreamReader(webResponse.GetResponseStream(),
Encoding.Default).ReadToEnd();
webResponse.Close();
......

This returns me a string of HTML as expected.

If I go to the website in an IE browser and View Source I see some
Javascript.

I want the webResponse string to return the javascript that I can see
in the browser script.

Can anyone help.

Thanks
Gavin
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

Your code snippet gives you exactly what the remote web server produced as
the web page contents. If you see script in the IE source, the script is
most likely also in the returned HTML string. The only exception I can think
of is when the initial portion of the script adds further script to the page
through DHTML object model.
 
J

Joerg Jooss

Hi,

I'm using the following code to request the html source from the
quoted site.

.....
string url = "http://www1.soccerstand.com/";
WebRequest webRequest = WebRequest.Create(url);
WebResponse webResponse = webRequest.GetResponse();
beginStr = new StreamReader(webResponse.GetResponseStream(),
Encoding.Default).ReadToEnd();
webResponse.Close();
.....

This returns me a string of HTML as expected.

If I go to the website in an IE browser and View Source I see some
Javascript.

I want the webResponse string to return the javascript that I can see
in the browser script.

I guess the page checks the user agent. Try pretending to be some
browser, like

webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE;
rv:1.7.5) Gecko/20041108 Firefox/1.0";

Cheers,
 

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

Top