PHP reading webpage

MrScott81

Golden Member
Aug 31, 2001
1,891
0
76
I'm trying to read the contents of a webpage with a php script. Normally, this is no problem, however, parts of the webpage I'm trying to read get updated with javascript on the page. Does anyone know of a way to have the javascript "process" before reading the page?
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
PHP runs server side. Javascript runs client side. The best route is probably to use a browser to load the page you want, then traverse the DOM to get what you need. I guess you could use a page generated in PHP and load an IFRAME with the page you want, but you'd still need Javascript on your page to get the data you want because, again, PHP is server side so once the page is loaded the server is done.
 

Aluvus

Platinum Member
Apr 27, 2006
2,913
1
0
PHP runs server side. Javascript runs client side. The best route is probably to use a browser to load the page you want, then traverse the DOM to get what you need. I guess you could use a page generated in PHP and load an IFRAME with the page you want, but you'd still need Javascript on your page to get the data you want because, again, PHP is server side so once the page is loaded the server is done.

Presumably the page is originating from a different server than the one the PHP script is running on, so from the perspective of the machine serving the page, the PHP script *is* the client.

Anyway.

What the OP needs is something like Mozilla's XULRunner, which is essentially a headless Firefox engine. Some related tools and suggestions here.