私はstackoverflowとウェブを検索しましたが、ここで何かが足りないに違いありません。探しているものが正確に見つかりませんでした。たぶんそれは他の何かと呼ばれています..私は最初のフォルダですべてをうまく取得しますが、他のフォルダから他のアイテムを取得しないこのコードを以下に示します..たとえば、最初の/の前にあるすべてを取得しますが、サイトmysiteがある場合。 com / folder2/folder2を取得しません。すべてがリンクされています。また、後方にも移動します。サイトの最長のリンクを入力すると、サイトの前面まで移動します。何が欠けているのかわかりませんが、ポインタがあれば素晴らしいと思います。このサイトは私がスクラップしようとしているjoomlaサイトです。
<?php function storelink($web,$taken) {
$query = "INSERT INTO scanned (web, taken) VALUES ('$web', '$taken')";
mysql_query($query) or die('Error, insert query failed');
}
$target_web = "mysite.com";
$userAgent = 'bobsbot(http://www.somebot.com/bot.html)';
// make the cURL request to $target_web
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $target_web);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
$html= curl_exec($ch);
if (!$html) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$web = $href->getAttribute('href');
storeLink($web,$target_web);
echo "<br />Link saved: $web";
} ?>