我是一名网络开发新手,目前正在从事网络爬虫项目。
这是我目前的代码:
<?php
include('simple_html_dom.php');
$URLarray = array(); //empty array that stores list of all Video Page URLs
function getLinks()
{ // this function goes to every VidBlock on the page and add the URL to the array
$html = file_get_html('https://www.myyouporn.com/');
$outerBlocksArray = $html->find('h2[class="entry-title"]');
foreach ($outerBlocksArray as $outerBlock) {
$URLarray[] = $outerBlock->find('a', 0)->href;
}
}
getLinks(); // WHAT I NEED IS --> THIS FUNCTION TO COMPLETE BEFORE MOVING AHEAD
print_r($URLarray);
?>
我正在使用 simple-html-dom-parser
库。
如何让我的 PHP 代码等待异步函数完成,然后再继续使用代码。