Solved

Reading source of a web page created dynamically

Posted on 2016-10-03
6
41 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Silverlight ERP To Angularjs,HTML5 3 56
Show MP4 file and close (HTA) 3 19
Html split(text) Part2 6 20
Stop Git from being my repository 1 14
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

680 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