简体   繁体   中英

fetch dynamically modified html content from page using ob_start and ob_get_clean()

Here's the situation. I need to fetch a page and execute the javascript.. then process the page in PHP. That javascript dynamically modifies the HTML of the page. Here's what I'm thinking of doing.

  • 1) Fetching the content using cURL/file_get_contents.
  • 2) Print the content so that Javascript gets executed.
  • 3) Use ob_start and ob_get_clean to fetch the modified content.

Code:

$contents = file_get_contents('http://...');
ob_start();
echo $contents;
$output = ob_get_clean();

Is there a way to achieve what I am attempting to do? I know javascript usually executes after page has loaded (and PHP is long gone).

带有.ajax() jQuery或带有纯JavaScriptXMLHttpRequest对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM