Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Tabelka file_get_contents i preg_match
omi
post 30.11.2017, 23:05:47
Post #1





Grupa: Zarejestrowani
Postów: 60
Pomógł: 0
Dołączył: 6.11.2017

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


Witam.

Chciałbym pobrać tabele z tej strony: https://www.money.pl/banki/elixir/
Mam taki kod:

  1. <?php
  2. $strona = file_get_contents('https://www.money.pl/banki/elixir/');
  3. echo '<pre>';
  4. preg_match('/<table class="tabela_elyxyr tabela big mO tlo_biel vag">(.*)<\/table>/s', $strona, $wynik);
  5. var_dump($wynik);
  6. ?>


Proszę mi napisać dlaczego nie wyświetla mi się tabelka na stronie wyświetla się tylko:

array(0) {
}

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
trueblue
post 2.12.2017, 17:26:43
Post #2





Grupa: Zarejestrowani
Postów: 6 803
Pomógł: 1827
Dołączył: 11.03.2014

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


Polecam lekturę: http://kawalekkodu.pl/post/the-tag-is-out-...domxpath-s01e01

  1. $html = file_get_contents('https://www.money.pl/banki/elixir/');
  2.  
  3. $dom = new DOMDocument;
  4. libxml_use_internal_errors(true);
  5. $dom->loadHTML($html);
  6. $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  7. libxml_clear_errors();
  8. $dom->encoding = 'UTF-8';
  9. $xpath = new DOMXPath($dom);
  10.  
  11. $trs = $xpath->query('//table[@class="tabela_elyxyr tabela big m0 tlo_biel vag"]//a[text()="Alior Bank" or text()="Bank Zachodni WBK"]/ancestor::tr');
  12. foreach($trs as $tr){
  13. echo $tr->nodeValue; // innerText
  14. echo $tr->C14N(); // innerHTML
  15. }


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 27.06.2025 - 19:43