Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]PHP Simple HTML DOM Parser - problem
seba1313
post 12.01.2015, 22:08:13
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 12.01.2015

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


Witam wszystkich!

Mam mały problem z PHP Simple HTML DOM Parser ( http://sourceforge.net/projects/simplehtmldom/files/ ), wyciągam zawartość diva z innej stronki kodem:

Kod
<?php
include_once('simple_html_dom.php');

$przedmiot = $_GET["przedmiot"];

$html = file_get_html('http://kecja.pl/'.$przedmiot);
$item = $html->find('#myDesc-1', 0)->outertext;
print_r($item);
?>


No i wszystko śmiga.

Stronka: http://kecja.pl/Mata_Edukacyjna.html
Efekt końcowy: http://bot.pe.hu/przedmiot.php?przedmiot=M...Edukacyjna.html

Gorzej jest jeśli w opisie produktu znajduje się odtwarzacz z YT.

Stronka: http://kecja.pl/Samoch%C3%B3d_Auto_Monster_Truck_RC.html
Efekt końcowy: http://bot.pe.hu/przedmiot.php?przedmiot=S...r_Truck_RC.html

Pokazuje się komunikat:

Cytat
Warning: file_get_contents(http://kecja.pl/Samochód_Auto_Monster_Truck_RC.html): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /home/u917930839/public_html/simple_html_dom.php on line 75

Fatal error: Call to a member function find() on a non-object in /home/u917930839/public_html/przedmiot.php on line 16


No i nie wiem w czym tkwi problem smile.gif
Go to the top of the page
+Quote Post
com
post 12.01.2015, 22:10:00
Post #2





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


http://stackoverflow.com/questions/697472/...-request-failed
Go to the top of the page
+Quote Post
seba1313
post 12.01.2015, 22:16:16
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 12.01.2015

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


Kurcze niestety w PHP jestem mega zielony, jakbyś dał radę przerobic mój kod lub jakoś łopatologicznie nakierować na rozwiązanie bylbym wdzięczny smile.gif
Go to the top of the page
+Quote Post
com
post 12.01.2015, 22:23:09
Post #4





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


użyj po prostu zamiast file_get_html tego z przykładu z Stack Overflow tzn cURL. a potem odebrane dane wstaw do Simple HTML DOM smile.gif
Go to the top of the page
+Quote Post
seba1313
post 12.01.2015, 22:55:47
Post #5





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 12.01.2015

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


Dzięki, śmiga biggrin.gif

//Edit

Mam jednak jeszcze mały problem, bo chcę przesłac getem adres jakim ma się wczytać, ale ten kod nie działa:

Kod
<?php
include_once('simple_html_dom.php');

$przedmiot = $_GET["przedmiot"];

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://kecja.pl/'.$przedmiot);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);

$html = str_get_html($query);
$item = $html->find('#myDesc-1', 0)->outertext;
print_r($item);
?>


Ma problemy z tym GETEM (umieszczenie adresu "na sztywno" działa bez problemu) smile.gif

Ten post edytował seba1313 12.01.2015, 23:16:45
Go to the top of the page
+Quote Post
com
post 12.01.2015, 23:39:18
Post #6





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


zrób sobie
  1. var_dump('http://kecja.pl/'.$przedmiot);
i spr czy się zgadza
Go to the top of the page
+Quote Post
seba1313
post 13.01.2015, 00:09:47
Post #7





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 12.01.2015

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


Niestety nie działa, chyba, że robię coś źle smile.gif
Go to the top of the page
+Quote Post
com
post 13.01.2015, 00:36:11
Post #8





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


chodzi o to http://ideone.com/5RYl3C i czy zwraca poprawny url wink.gif
Go to the top of the page
+Quote Post
seba1313
post 13.01.2015, 00:46:50
Post #9





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 12.01.2015

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


Tak, zwraca poprawny URL smile.gif
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: 25.04.2025 - 06:59