Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Uzycie metody find z klasy Simple html DOM w petli foreach
Forum PHP.pl > Forum > PHP
Raven1122
Witam, mam taki kod:


  1. <?php
  2. require_once("shd.php");
  3. $link = "http://www17.zippyshare.com/v/17073605/file.html";
  4. $html = file_get_html($link);
  5. foreach($html->find('font') as $element)
  6. echo $element->plaintext . '<br>';
  7.  
  8. ?>


No i chodzi o to, że wyciąga mi wszystkie elementy "font", a chciałbym się dowiedzieć jak wyciągnąć tylko te, które ja chcem. Zwraca mi:

  1. Remember Me |
  2. You have requested the file:
  3. Name:
  4. Flo Rida ft. Jennifer Lopez - Sweet Spot (TAITO Bootleg) www.StrefaMp3.eu.mp3
  5. Size:
  6. 10.51 MB
  7. Uploaded:
  8. 06-10-2012 09:37
  9. Last download:
  10. 18-03-2013 21:39
  11. Click the Play button to hear a sample of this MP3
  12. Advertisement
  13. Zippyshare.com News:
  14. To upload a file just follow these simple steps:
  15. Benefits of using Zippyshare:
  16. Zippyshare.com is completely free, reliable and popular way to store files online. We offer fast download speeds. The maximum filesize for a single file is 200 MB. The file can be downloaded at any time and as often as you need it. File Life: 30 days after no activity. No ridiculous queues! No limits!
  17. Report illegal files, please click here and send full link to us!
  18. Š 2006-2012 Zippyshare.com. All rights reserved.


A chce linie tylko: 3, 5, 7, 9


Jak zrobić by wyciągneło te linie??
_Borys_
  1. $link = "http://www17.zippyshare.com/v/17073605/file.html";
  2. $html = file_get_html($link);
  3. $font = $html->find('div[class=left] font');
  4. echo $font[2]->plaintext . '<br>';
  5. echo $font[4]->plaintext . '<br>';
  6. echo $font[6]->plaintext . '<br>';
  7. echo $font[8]->plaintext . '<br>';
Raven1122
Dobra, Dziękuje działa, ale teraz jescze:

Mam taki kod:

  1. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  2. </head>
  3. <?php
  4. require_once("shd.php");
  5. $link = "http://www17.zippyshare.com/v/17073605/file.html";
  6. $html = file_get_html($link);
  7. $font = $html->find('div[class=left] font');
  8. echo $font[2]->plaintext . '<br>' . $font[4]->plaintext . '<br>' . $font[6]->plaintext . '<br>' . $font[8]->plaintext . '<br>';
  9.  
  10. $script = $html->find('div[class=right] script');
  11. echo $script[0];
  12.  
  13.  
  14.  
  15. ?>
  16. <a id="dlbutton" href=""><?php echo $font[2]->plaintext; ?></a>
  17. </body>
  18. </html>


Zrodlo wyglada tak:
  1. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  2. </head>
  3. Flo Rida ft. Jennifer Lopez - Sweet Spot (TAITO Bootleg) www.StrefaMp3.eu.mp3<br>10.51 MB<br>06-10-2012 09:37<br>19-03-2013 13:44<br>
  4. <script type="text/javascript"> var n = 2; var b = 857863; document.getElementById('dlbutton').href = "/d/17073605/"+(n + n * 2 + b)+"
  5. 3/Flo%20Rida%20ft.%20Jennifer%20Lopez%20-%20Sweet%20Spot%20%28TAITO%20Bootleg%29%20www.StrefaMp3.eu.mp3"; </script>
  6. <a id="dlbutton" href="">Flo Rida ft. Jennifer Lopez - Sweet Spot (TAITO Bootleg) www.StrefaMp3.eu.mp3</a>
  7. </body>
  8. </html>


No i niestety nie dodaje linku ze skryptu do odnośnika "dlbutton". Dlaczego tak jest?

BUMP

FireBug wywala błąd, że getElementById jest null

  1.  
  2. TypeError: document.getElementById(...) is null
  3. [Wstrzymuj na tym błędzie]
  4.  
  5. ...n = 2; var b = 676652; document.getElementById('dlbutton').href = "/d/17...
Fifi209
Bo javascript chce to zrobić zanim jeszcze zostanie wczytane całe drzewo html

Używasz jQuery a takie świństwa piszesz...

[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(
  2. function()
  3. {
  4. // jesteś pewien że masz wczytane drzewo
  5. });
[JAVASCRIPT] pobierz, plaintext
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.