Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Simple HTML DOM i wysyłanie maila
cox
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 29.10.2005

Ostrzeżenie: (0%)
-----


Witam,
niestety skrypt w którym pomógł mi ostatnio Kofel (w tym temacie http://forum.php.pl/index.php?showtopic=211830) nie spełnia swego zadania gdyż kanał rss z którego były pobierane informacje miał duże opóźnienie nawet po 2-3 godziny co jest dla mnie nie do przyjęcia. Na internecie znalazłem taki skrypt:
  1. <?php
  2. // Pull in PHP Simple HTML DOM Parser
  3. include("simplehtmldom/simple_html_dom.php");
  4.  
  5. // Settings on top
  6. $sitesToCheck = array(
  7. // id is the page ID for selector
  8. array("url" => "http://www.stronadosubskrypcji.com", "selector" => ".header")
  9. );
  10. $savePath = "cachedPages/";
  11. $emailContent = "";
  12.  
  13. // For every page to check...
  14. foreach($sitesToCheck as $site) {
  15. $url = $site["url"];
  16.  
  17. // Calculate the cachedPage name, set oldContent = "";
  18. $fileName = md5($url);
  19. $oldContent = "";
  20.  
  21. // Get the URL's current page content
  22. $html = file_get_html($url);
  23.  
  24. // Find content by querying with a selector, just like a selector engine!
  25. foreach($html->find($site["selector"]) as $element) {
  26. $currentContent = $element->plaintext;
  27. }
  28.  
  29. // If a cached file exists
  30. if(file_exists($savePath.$fileName)) {
  31. // Retrieve the old content
  32. $oldContent = file_get_contents($savePath.$fileName);
  33. }
  34.  
  35. // If different, notify!
  36. if($oldContent && $currentContent != $oldContent) {
  37. // Here's where we can do a whoooooooooooooole lotta stuff
  38. // We could tweet to an address
  39. // We can send a simple email
  40. // We can text ourselves
  41.  
  42. // Build simple email content
  43. $emailContent = "David, the following page has changed!\n\n".$url."\n\n";
  44. }
  45.  
  46. // Save new content
  47. file_put_contents($savePath.$fileName,$currentContent);
  48. }
  49.  
  50. // Send the email if there's content!
  51. if($emailContent) {
  52. // Sendmail!
  53. mail("mail@mailnajakimawyslac.com","Sites Have Changed!",$emailContent,"From: alerts@davidwalsh.name","\r\n");
  54. // Debug
  55. echo $emailContent;
  56. }
  57. ?>


Lecz też nie funkcjonuje. Każdy nagłówek newsa w kodzie jest w
  1. <SPAN CLASS="header">
  2.  
  3. Jakiś news</span>
. Na stronie z której pobieram informacje jest 10 newsów lecz otwierając plik w katalogu cachedPages znajduje się tylko nagłówek najstarszego, jednego news'a. Nawet ten jeden nagłówek nie wysyła na maila. W czym problem ?
Z góry dziękuję za pomoc.

Ten post edytował cox 29.01.2013, 19:27:09
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 07:35