Ето този код взима връзките от дадена страница, а аз искам малко хелп да го модифицирам и да взима емаилите от дадена страница!
<?php
function storeLink($url, $gathered_from) {
/* $query = "INSERT INTO links
(url, gathered_from)
VALUES
('$url', '$gathered_from')";
mysql_query($query) or die('Error, insert query failed');*/
echo $url.'<br>';
}
$target_url = "страницата от която искаме да вземем връзките";
$userAgent = 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
// Правим cURL заявка към $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);
curl_close($ch); // Слага край да $data.
if (!$html) {
echo "<br />cURL error number:" . curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
// разбор (parse) html в DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
// взимаме цялата страница
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
storeLink($url, $target_url);
//echo "<br />Link stored: $url";
}
?>
<?php
function storeLink($url, $gathered_from) {
/* $query = "INSERT INTO links
(url, gathered_from)
VALUES
('$url', '$gathered_from')";
mysql_query($query) or die('Error, insert query failed');*/
echo $url.'<br>';
}
$target_url = "страницата от която искаме да вземем връзките";
$userAgent = 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
// Правим cURL заявка към $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);
curl_close($ch); // Слага край да $data.
if (!$html) {
echo "<br />cURL error number:" . curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
// разбор (parse) html в DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
// взимаме цялата страница
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
storeLink($url, $target_url);
//echo "<br />Link stored: $url";
}
?>