Solved

Reading source of a web page created dynamically

Posted on 2016-10-03
6
35 Views
Last Modified: 2016-10-08
I would like to be able to read the contents of a table on a web page.  
I can use the WebCient.OpenRead to read the source HTML code.  Using FireFox I can view the source and they seem to be identical.  So far so good.
Also using Firefox I can inspect an element - the table I want to read.  The ID of the table doesn't exist in the source code, in fact no tables exist in the source code of the website.  Looking at the source I think there is a frame which is being created dynamically and this frame then has the contents copied and pasted into a div.

In the source from the WebClient.OpenRead I get:   <div id="xyz_abc_div"></div>
In the browser (inspect element) I see a load more HTML with the table I want.

Question.  How can I get the contents of this dynamically filled div ?
0
Comment
Question by:AndyAinscow
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41826879
It is more likely that the data is being loaded thru AJAX / javascript after the page is loaded.  It would not show in the view source in that case.  That is a common method these days.  The only way to get that content is to run the javascript that makes the request.
0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 41827005
Hmmm, thanks.

I think it is javascript (numbers of .js scripts being loaded).  I also see a function called LoadFrame with a frame and then (snippet)

                  var iframe = document.getElementById('xyz_frame');
                  iframe.src = 'path goes here';
                  iframe.onload = function(){
                        xyz_copyFrameToDiv(iframe, 'xyz_div')


>>The only way to get that content is to run the javascript that makes the request.
I understand the words but the result exists in the browser, can't I get at that.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
ID: 41827028
The browsers run javascript and your function does not.  WebCient.OpenRead basically just reads a single file from a 'resource'.  It does not do any processing.  https://msdn.microsoft.com/en-us/library/ms144209(v=vs.110).aspx    The javascript, CSS, and images are often in other files which are not loaded with the original request.  In addition, even if you download the javascript files, you must have a javascript interpreter and the HTML DOM to make any sense out of them.  Javascript is a programming language, just reading the source file doesn't create the results.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 44

Accepted Solution

by:
AndyAinscow earned 0 total points
ID: 41827632
Found what I wanted.  I can use the DocumentText property of a WebBrowserControl to get the currently used HTML of the page after the browser has run the js functions.
0
 
LVL 44

Author Closing Comment

by:AndyAinscow
ID: 41834916
Thanks for the info on how it is working in the background, it made me think of an alternative to get what I wanted.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41835186
You're welcome, glad to help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question