Witam,
z racji tego, że to mój pierwszy post chciałbym się serdecznie przywitać.
Mój problem polega na tym, iż chcę być na bieżąco z pewnymi news'ami na danej stronie.
Znalazłem w internecie skrypt z wykorzystaniem Simple HTML DOM, który sprawdza czy jest coś nowego i jeżeli jest wysyła maila z informacją. Kod skryptu:
<?php
// Pull in PHP Simple HTML DOM Parser
include("simplehtmldom/simple_html_dom.php");
// Settings on top
$sitesToCheck = array(
// id is the page ID for selector
array("url" => "http://www.stronadosubskrypcji.com", "selector" => ".header")
);
$savePath = "cachedPages/";
$emailContent = "";
// For every page to check...
foreach($sitesToCheck as $site) {
$url = $site["url"];
// Calculate the cachedPage name, set oldContent = "";
$fileName = md5($url);
$oldContent = "";
// Get the URL's current page content
$html = file_get_html($url);
// Find content by querying with a selector, just like a selector engine!
foreach($html->find($site["selector"]) as $element) {
$currentContent = $element->plaintext;
}
// If a cached file exists
if(file_exists($savePath.$fileName)) {
// Retrieve the old content
$oldContent = file_get_contents($savePath.$fileName);
}
// If different, notify!
if($oldContent && $currentContent != $oldContent) {
// Here's where we can do a whoooooooooooooole lotta stuff
// We could tweet to an address
// We can send a simple email
// We can text ourselves
// Build simple email content
$emailContent = "David, the following page has changed!\n\n".$url."\n\n";
}
// Save new content
file_put_contents($savePath.$fileName,$currentContent);
}
// Send the email if there's content!
if($emailContent) {
// Sendmail!
mail("mail@mailnajakimawyslac.com","Sites Have Changed!",$emailContent,"From: alerts@davidwalsh.name","\r\n");
// Debug
echo $emailContent;
}
?>
Niestety nie działa i nie wiem w czym leży błąd. Na stronie, z której chce pobrać informację jest 10 news'ów. Nagłówek każdego jest w następujący sposób
<SPAN CLASS="header">
Jakiś news</span>
Po otwarciu pliku w folderze cachedPages widnieje nagłówek tylko jednego, najstarszego news'a.
Nie wysyła maila nawet z tym jednym nagłówkiem.
Ma ktoś jakiś pomysł?
Z góry dziękuję za pomoc.