Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][CURL] Wydobycie domyślnej wartości pola tekstowego
AdBlock
post
Post #1





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 26.05.2012

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


Oto fragment źródła pewnej strony:
  1. <textarea rows='10' cols='80' name='f_content'>
  2. Jakiś tekst</textarea>


Jak wydobyć "Jakiś tekst" za pomocą curla?
Kompletnie nie mam pomysłu na to. Zmienna f_content nic nie zwraca.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
pitu
post
Post #2





Grupa: Zarejestrowani
Postów: 476
Pomógł: 96
Dołączył: 10.04.2008
Skąd: Koszalin

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


Pobierz źródło strony po przez file_get_contents lub jeżeli wykonujesz na owej stronie jakieś operacje curlem. Następnie wartość pola tekstowego za pomocą wyrażenia regularnego lub za pomocą:
http://simplehtmldom.sourceforge.net/
Go to the top of the page
+Quote Post
b4rt3kk
post
Post #3





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

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


W zależności od budowy strony. Jeśli jest zbudowana zgodnie ze standardem XML-owym to możesz użyć PHP-owego XML parsera. Jeśli się tutaj nie sprawdzi to zbuduj odpowiednie wyrażenie regularne. Coś w stylu:

  1. preg_match('#<textarea>(.*)<\/textarea>#', $string, $matches);


Oczywiście to tylko przykład, bo wyrażenie będzie znacznie bardziej rozbudowane.
Go to the top of the page
+Quote Post
AdBlock
post
Post #4





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 26.05.2012

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


Fragment kodu:
  1. $c = curl_init();
  2.  
  3. curl_setopt($c, CURLOPT_URL, "strona/login.php");
  4. curl_setopt($c, CURLOPT_POST, 1);
  5. curl_setopt($c, CURLOPT_POSTFIELDS, 'user=*axi*&pass=plackisabe&cookie=on
  6. '); //dane do wyslania
  7. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($c, CURLOPT_HEADER , 1);
  9. curl_setopt($c, CURLOPT_COOKIEFILE, './cookie.txt');
  10. curl_setopt($c, CURLOPT_COOKIEJAR,'./cookie.txt');
  11. curl_setopt($c, CURLOPT_URL, "strona/edit.php");
  12. curl_setopt($c, CURLOPT_POST, 1);
  13. curl_setopt($c, CURLOPT_POSTFIELDS, 'f_content='.$_GET['nazwa'].'');
  14. $page = curl_exec($c);
  15. curl_close($c);
  16. echo 'Wynik: <br>' .$page;
  17. echo file_get_html($page)->plaintext;

echo $page wyświetla tak jak należy stronę, a file_get_html zwraca następujący błąd:
Cytat
Warning: file_get_contents() [function.file-get-contents]: open_basedir restriction in effect. File(HTTP/1.1 200 OK Date: Mon, 17 Jun 2013 19:01:07 GMT Server: Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 X-Powered-By: PHP/5.3.25 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 <html style="overflow:scroll;"> <head> <STYLE type="text/css"> a:link { font-weight:bold; color: #804000; text-decoration:none; } a:visited { font-weight:bold; color: #804000; text-decoration:none; } a:active { font-weight:bold; color: #0082BE; text-decoration:none; } a:hover { font-weight:bold; color: #0082BE; text-decoration:none; } </STYLE> </head> in /public_html/simple_html_dom.php on line 75

Warning: file_get_contents(HTTP/1.1 200 OK Date: Mon, 17 Jun 2013 19:01:07 GMT Server: Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 X-Powered-By: PHP/5.3.25 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 <html style="overflow:scroll;"> <head> <STYLE type="text/css"> a:link { font-weight:bold; color: #804000; text-decoration:none; } a:visited { font-weight:bold; color: #804000; text-decoration:none; } a:active { font-weight:bold; color: #0082BE; text-decoration:none; } a:hover { font-weight:bold; color: #0082BE; text-decoration:none; } </STYLE> </head> <style type="text/css"> .hidden { display: none; } .unhidden { display: block; } </style in /public_html/simple_html_dom.php on line 75

Co jest grane? (IMG:style_emoticons/default/wink.gif) Jak wpiszę sztywny link do tej funkcji - też wszystko śmiga, ale strona ta wymaga autoryzacji, dlatego nie mogę wpisać sztywnego linku.

Ten post edytował AdBlock 17.06.2013, 20:04:33
Go to the top of the page
+Quote Post
gorden
post
Post #5





Grupa: Zarejestrowani
Postów: 486
Pomógł: 101
Dołączył: 27.06.2010

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


baaka. Ty nie masz używać cURLa i file_get_contents tylko jedno albo drugie.

czyli

  1. $html = file_get_html('strona/login.php');
  2.  
  3. echo $textarea = $html->find('textarea[name=f_content]')->innertext;
Go to the top of the page
+Quote Post

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: 23.08.2025 - 19:30