All, I have the following C# code (listed at the end of the message) which does list all the image tags on a given page request. The problem is it does not list image tags that are created on the client via external .js files, for example if the following was in an external .js
document.writeln("<img src=\"images/136195-gk-shirt-away.jpg\" />"); I could load each js file but I think I am starting to bark up the wrong tree with this approach. I cannot guarantee if the images have been written by document.writeln or they have been added via the DOM or the many otherways there are to do this. Can anyone think of a better way. public void TestWebRequest() { WebRequest req = WebRequest.Create("http://localhost:2178/Image/Default.aspx"); ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) { return true; }; StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream()); StringBuilder sb = new StringBuilder(); string line = string.Empty; while ((line = sr.ReadLine()) != null) { if (line.Length > 0) sb.Append(line); } _site = sb.ToString(); Regex r = new Regex("<img[^>]+>"); MatchCollection mcl = r.Matches(_site); foreach (Match m in mcl) { foreach (Group g in m.Groups) { Console.WriteLine(g.Value); } } } [EMAIL PROTECTED]
From: Patrick Steele <[EMAIL PROTECTED]> Reply-To: "Discussion of advanced .NET topics." <ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] HTTP help Date: Wed, 8 Mar 2006 10:12:20 -0500 What about having some automated process run IE and request the pages you want to test. Then parse through your IIS logs and look for 404's. Kind of a round-about way to do it, but at least this way you leave the HTML parsing and HTTP requests to IE. -- Patrick Steele Microsoft .NET MVP http://weblogs.asp.net/psteele -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Paul Cowan Sent: Wednesday, March 08, 2006 9:58 AM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] HTTP help Thanks Peter, It is a long and complicated story but as simply as I can put it, we have to ensure that a particular .jpg file is on a requested page. My first thoughts were to use javascript to parse the DOM but we cannot guarantee that the element was rendered by an external .js file. That is the requirement put as simply as I can. We want to automate this process. The Html that is coming back is not XHTML compliant or I would consider using the XmlHTTPRequest object. Can you think of a simpler way to achieve this than examining the HttpResponse. Thanks Paul [EMAIL PROTECTED] >From: Peter Ritchie <[EMAIL PROTECTED]> >Reply-To: "Discussion of advanced .NET topics." ><ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> >To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM >Subject: Re: [ADVANCED-DOTNET] HTTP help >Date: Wed, 8 Mar 2006 09:49:08 -0500 > >I assume you mean resources linked to via the likes of <img >href="Image1.jpg">. Those "links" are retrieved as separate HTTP >requests; and whenever the browser feels like it. There's no guarantee >they'll be requested adjacent to the original page's request either. > >If you want to find out what dependant files page1.aspx links to you'll >have to parse the HTML returned from page1.aspx looking for "link" >elements like IMG or LINK. > >Why do you need to do this? I ask because it influences how you would >go about achieving this. > >On Wed, 8 Mar 2006 14:36:46 +0000, Paul Cowan <[EMAIL PROTECTED]> >wrote: > > >Hi all, > > > >Can anyone help me with the following requirements? We want to parse > >an HTTP request for a web page and display all the constituent parts > >that >make > >up the web page. That is I want to display all the additional > >requests >that > >are made to make up the whole page (i.e. css, images and javascript >files). > >Say I make a request for page1.aspx then the system would log that it > >is made up of the following resources: > > > >Default.css > >Modern.css > >Image1.jpg > >Script.js > >Etc., etc. > > > >I have no idea how to achieve this, does anybody know?? > >=================================== >This list is hosted by DevelopMentorR http://www.develop.com > >View archives and manage your subscription(s) at >http://discuss.develop.com =================================== This list is hosted by DevelopMentorR http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
=================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com