Solved

Reading source of a web page created dynamically

Posted on 2016-10-03
6
23 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

910 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now