Accessing the javascript on a webpage using Webrequest/Webresponse

  • Thread starter Thread starter gizmo
  • Start date Start date
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
 
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.
 
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,
 
Back
Top