0
私はこのループを解決する方法を理解するいくつかの問題を抱えている:再帰的または単純なPHPのループ
私は自分のために小さなスクラッパーを開発していると私はどのようにすべてまで2つのメソッド内のループに把握しようとしていますリンクはウェブサイトから検索されます。
私はすでに最初のページからのリンクを取得していますが、問題は、私はすでに抽出された新しいリンクを検証するためのループを作ることができないということである。ここでは
は私のコードです:
$scrap->fetchlinks($url);//I scrap the links from the first page from a website
//for each one found I insert the url in the DB with status = "n"
foreach ($scrap->results as $result) {
if ($result) {
echo "$result \n";
$crawler->insertUrl($result);
//I select all the links with status = "n" to perform a scrap the stored links
$urlStatusNList = $crawler->selectUrlByStatus("n");
while (sizeof($urlStatusNList > 1)){
foreach($urlStatusNList as $sl){
$scrap->fetchlinks($sl->url); // I suppose it would retrieve all the new sublinks
$crawler->insertUrl($sl->url); // insert the sublinks in the db
$crawler->updateUrlByIdStatus($sl->id, "s"); //update the link scraped with status = "s", so I will not check these links again
//here I would like to return the loop for each new link in the db with status='n' until the system can not retrieve more links and stops with the script execution
}
}
}
}
どのような種類のヘルプも大歓迎です。前もって感謝します !あなたはこれを意味するか:
あなたはこのdo
{
grab new links and add them to database
} while(select all not yet extracted from database > 0)
ような何かを探している擬似コードで
...再帰なしにして起こって答えてくれてありがとうを続けるのだろうか? do { $ scrap-> fetchlinks($ url); foreach($ scrap-> results as $ result){ if($ result){ echo "$ result \ n"; $ crawler-> insertUrl($ result); } } } while($ crawler-> selectUrlByStatus( "n")> 1); 感謝! – rpa
@rpaはい、これらの行のなかにあるはずです...(コードが検証するかどうかは実際には確認しませんでした)。 – Frankie