Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> simple_html_dom zapis do bazy, jak zapisać
michalbd93
post 2.12.2018, 15:38:51
Post #1





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

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


  1. $html = file_get_contents('https://www.strona.pl');
  2. //Create a new DOM document
  3. $dom = new DOMDocument;
  4.  
  5. //Parse the HTML. The @ is used to suppress any parsing errors
  6. //that will be thrown if the $html string isn't valid XHTML.
  7. @$dom->loadHTML($html);
  8.  
  9. //Get all links. You could also use any other tag name here,
  10. //like 'img' or 'table', to extract other tags.
  11. $links = $dom->getElementsByTagName('a');
  12.  
  13. //Iterate over the extracted links and display their URLs
  14. foreach ($links as $link){
  15. // tutaj chce zapisać do bazy danych informacje normalnie sie wyswitlają ale nie zapisuje do bazy
  16. }
Go to the top of the page
+Quote Post
viking
post 2.12.2018, 16:25:34
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Po pierwsze gdzie tu masz simple_html_dom? A po drugie jak ten zapis robisz?


--------------------
Go to the top of the page
+Quote Post
michalbd93
post 2.12.2018, 17:36:12
Post #3





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

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


simple mam wyżej to jest tylko kawałek kodu
to jest w foreach
echo $link->getAttribute('href');

i chciałbym zapisać to do bazy
$z = $mysqli->query("INSERT INTO test SET nazwa='$link'");

Ten post edytował michalbd93 2.12.2018, 17:37:07
Go to the top of the page
+Quote Post
viking
post 2.12.2018, 17:54:18
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


To skoro używasz simple to po co to wstawiasz domdocument? Masz połączenie? Jakieś błędy w logach? Podaj więcej informacji jak to robisz a nie każesz zgadywać.


--------------------
Go to the top of the page
+Quote Post
michalbd93
post 2.12.2018, 18:04:13
Post #5





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

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


  1. <?php
  2. require("simple_html_dom.php");
  3.  
  4. $html = file_get_contents('https://www.wp.pl');
  5. //Create a new DOM document
  6. $dom = new DOMDocument;
  7.  
  8. //Parse the HTML. The @ is used to suppress any parsing errors
  9. //that will be thrown if the $html string isn't valid XHTML.
  10. @$dom->loadHTML($html);
  11.  
  12. //Get all links. You could also use any other tag name here,
  13. //like 'img' or 'table', to extract other tags.
  14. $links = $dom->getElementsByTagName('a');
  15.  
  16. //Iterate over the extracted links and display their URLs
  17. foreach ($links as $link){
  18.  
  19. //Extract and show the "href" attribute.
  20. echo $link->getAttribute('href');
  21.  
  22. }
  23.  
  24. ?>

powiedzmy ze to jest cały kod i chciał bym te wyniki z $link zapisać do bazy
mam połączenie z baza danych ale jak chce tam zapisać to wyskakuje bład
Catchable fatal error: Object of class DOMElement could not be converted to string in /prz/index.php on line 35


mam nadzieję że dobrze opisałem

Ten post edytował michalbd93 2.12.2018, 18:20:55
Go to the top of the page
+Quote Post
viking
post 2.12.2018, 19:10:43
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


$z = $mysqli->query("INSERT INTO test SET nazwa='$link->getAttribute('href')'");
Na przyszłość podawaj błędy. I dalej nigdzie w tym kodzie nie używasz simple html


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

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: 16.04.2024 - 07:51