Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Read contents from a webpage

Featured Replies

For reading the contents of a webpage i am using the code.....

 

<?php

 

$link = "http://www.xyz.com";

$file = file_get_contents($link);

echo $file;

?>

But the problem is that i am not able to read the ajax stuffs whichs loads after sometime....

So , i am getting just a blank table as the contents.....

with all the values eual to " "(blank)

Is there any way to do so using php ???

plz inform me if there is some way to do so.... as soon as possible.... :)

pricecheck.php

Not exactly, you'd need to use/steal some of their javascript to make it work as well. Otherwise you could make your own table from their XHR data...

 

<?php

$link = "http://www.nseindia.com/marketinfo/equities/ajaxGetQuote.jsp?symbol=ABAN&series=EQ";

$file = file_get_contents($link);


$dump = explode(';', $file);
echo "<pre>";
print_r($dump);
echo "</pre>";

?>

  • Author

Can we use ajax to read the contents of a webpage.....

 

so that it could wait till the webpage loads completely....

 

Plz tell me if there is any way to do so ...:)

I dont know of any javascript enabled method of getting http data. I would take the table off their site and fill it using the code I posted above, it will take you some time to match up each field but you could refer back to their javascript file to see what goes where.

Hi atiprashant,

 

You can read the entire current contents of a web page using this simple javascript snippet:

 

pagecontents = document.getElementsByTagName('BODY');

 

This will store the page contents to variable 'pagecontents' as it stands at the time of calling the snippet, not as it stands when the page loads, so any AJAX calls will be reflected here. You can then use the various javascript string manipulation methods to extract the information you want (if needs be) and then send the resulting information as variable(s) attached to a call to an external php script using AJAX.

 

Remember that php is processed server side before the page is sent to the browser, so anything that you need to access via php must be sent to the server, it cannot be done client side.

  • Author

but the problem is that we can use AJAX only for calling the files of the same domain.....

 

 

and in any other case it shows the contents before the entire page loads completely....:)

So you are trying to access the source code for a domain other than your own? If you are allowed access to this other domain then there will be much better ways of doing whatever it is you are trying to achieve. If you are not, then you probably shouldn't be doing it anyway...

  • Author

but the other domain is not mines.....

 

i am just trying to get the current stock prices from another website so that i can use it in mine...

 

but for that i cant use AJAX...

 

so i am asking is there any way code which allows the page to load completely and then we can read out the contents using 'explode' etc...

  • 2 weeks later...
  • Author

I dont know of any javascript enabled method of getting http data. I would take the table off their site and fill it using the code I posted above, it will take you some time to match up each field but you could refer back to their javascript file to see what goes where.

 

That will not work for sure ....

 

It will just echo out the contents of the page when it is called.... and not how it looks when the page loads completely...i.e when http status is 200

but the other domain is not mines.....

 

i am just trying to get the current stock prices from another website so that i can use it in mine...

 

but for that i cant use AJAX...

 

so i am asking is there any way code which allows the page to load completely and then we can read out the contents using 'explode' etc...

 

why not ask them if there is a way of them letting you have a feed of the information? or shouldn't you be ripping off their information and why they have supplied it in the manner that they have?

That will not work for sure ....

 

It will just echo out the contents of the page when it is called.... and not how it looks when the page loads completely...i.e when http status is 200

 

It will work, you take the code for the table and populate it using the same XHR as their site.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.