-1
<?php
$homepage = file_get_contents('https://finance.yahoo.com/quote/0016.HK/news p=0016.HK"');
echo $homepage;
?>
<script type="text/javascript">
function test(){
..... 
}

The script was executed before the website load all the contents and thus, I can't get all the content after running the script. How can I fully get the content from the website first and then run the script? thanks!

Yan
  • 7
  • 7

1 Answers1

2
<script type="text/javascript">
document.addEventListener( 'DOMContentLoaded', function( event ) {
    function test(){
     console.log("DOM loaded");
    }
});
</script>
Sébastien S.
  • 1,444
  • 8
  • 14
  • it does not work, as the website will show the first three news and then show all news... – Yan Apr 13 '18 at 07:52
  • This function will let you control your functions. If you imported other javascript functions from `file_get_contents` and included them in your content, those javascript functions are out of the DOMContentLoaded scope. – Sébastien S. Apr 13 '18 at 07:55