Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Curl pobieranie terści ze strony i wysyłanie do bazy mysql
ejot
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


Witam, potrzebuje ze strony pobrać dane i zapisać w bazie mysql.

<?php
$c = curl_init();
curl_setopt($c, CURLOPT_URL,'http://www.eco-institute.pl/programy.html');
curl_exec($c);
?>

Powyższy kod pobiera mi całą stronę. Nie wiem jak pobrać poszczególne <div class="right"> i wrzucić do mysql.
Proszę o pomoc.
Go to the top of the page
+Quote Post
Xelah
post
Post #2





Grupa: Zarejestrowani
Postów: 139
Pomógł: 24
Dołączył: 12.05.2013
Skąd: Hamburg

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


Interesuje cię DOM i XPATH.
http://php.net/manual/en/book.dom.php

http://php.net/manual/en/class.domxpath.php

http://www.w3schools.com/xpath/default.asp

PS. Poszukaj na tym formu. Temat był już przerabiany dziesiątki razy.

Ten post edytował Xelah 15.06.2015, 11:33:05
Go to the top of the page
+Quote Post
ejot
post
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


Witam mam cos takiego czy mysle w dobrym kierunku - prosze o pomoc.

<?php
$c = curl_init();
curl_setopt($c, CURLOPT_URL,'http://www.eco-institute.pl/programy.html');
curl_exec($c);

$file = $DOCUMENT_ROOT. "http://www.eco-institute.pl/programy.html";
$doc = new DOMDocument();
$doc->loadHTMLFile($file);

$xpath = new DOMXpath($doc);

$elements = $xpath->query("div class="right"");

$db = new Mysqli("localhost", "root", "", "");
$elements = (int)$_POST['divtxt'];
$query = "INSERT INTO data SET mydata='$divtxt'";
$db->query($query);
}
?>
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




1) Uzywaj bbcode do wstawianego kodu na forum.
2) A zmienną $divtxt to skad wytrzasnales?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
ejot
post
Post #5





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


Witam czy mógłby ktos mnie naprowadzić co i jak bo sie pogubiłem.

Potrzebuje skrypt który pobierze mi odpowiedznie dane html ze strony i wrzuci je do bazy mysql, prosze om pomoc.
Go to the top of the page
+Quote Post
rad11
post
Post #6





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


I skad ktos ma wiedziec jakie dane potrzebujesz?
Go to the top of the page
+Quote Post
ejot
post
Post #7





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


np ze strony http://www.eco-institute.pl/programy.html :

<h1 class="ng"> Programy</h1>

<div class="text">
Go to the top of the page
+Quote Post
rad11
post
Post #8





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


  1. $html = file_get_contents("http://www.eco-institute.pl/programy.html");
  2. preg_match_all("'<h1 class=\"ng\">(.*?)</h1>'si", $html, $header);
  3. preg_match_all("'<div class=\"text\">(.*?)</div>'si", $html, $div);
  4.  
  5. var_dump($header[0][0]);
  6. var_dump($div[0][0]);
Go to the top of the page
+Quote Post
ejot
post
Post #9





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


Dzięki za kod a jak zrobić to z CURL.
Go to the top of the page
+Quote Post
rad11
post
Post #10





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


A czemu koniecznie chcesz uzyc do tego CURL ? Przeciez nie musisz wysylac nic POST`em ani GET`em?

  1. function get_data($url) {
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5. $data = curl_exec($ch);
  6. preg_match_all("'<h1 class=\"ng\">(.*?)</h1>'si", $data, $header);
  7. preg_match_all("'<div class=\"text\">(.*?)</div>'si", $data, $div);
  8.  
  9. curl_close($ch);
  10.  
  11. return array_merge($header[0][0], $div[0][0]);
  12. }
  13. get_data('http://www.eco-institute.pl/programy.html');


Ten post edytował rad11 23.06.2015, 09:35:58
Go to the top of the page
+Quote Post
ejot
post
Post #11





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


Chce wysłać to do lokalnej bazy danych mysql.
Go to the top of the page
+Quote Post
rad11
post
Post #12





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


Do tego nie jest Ci potrzebny curl skoro to baza lokalna.
Go to the top of the page
+Quote Post
ejot
post
Post #13





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 15.06.2015

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


Potrzebuje skrypt który pobierze poniższe wartości ze strony Curlem zapętli dla <div id="container-id"> <span>nr:<br /> 4</span></div> wrzuci do mysql i wyświetli z moje bazy na mojej stronie. Prosze o pomoc bo nic mi nie wychodzi.

  1. 1.
  2. <div id="container-media">
  3. <div style="height: 400px;">
  4. <img src="media/1.png" />
  5. </div>
  6.  
  7. 2.
  8. <div id="container-id">
  9. <span>nr:<br /> 4</span>
  10. </div>
  11.  
  12. 3.
  13. <div id="container-content">
  14. <span>questionmark.gifquestionmark.gif</span>
  15. </div>
  16.  
  17.  
  18. 4.
  19. <tr class="answerRow">
  20. <td>
  21. <div class="blueSquare qAnswer">A</div>
  22. </td>
  23. <td style="vertical-align: middle; ">
  24. <div class="qAnswer">aaa</div>
  25. </td>
  26.  
  27. 5.
  28. <tr class="answerRow">
  29. <td>
  30. <div class="blueSquare qAnswer">B</div>
  31. </td>
  32. <td style="vertical-align: middle;">
  33. <div class="qAnswer">bbb</div>
  34. </td>
  35. </tr>
  36.  
  37. 6.
  38. <tr class="answerRow">
  39. <td>
  40. <div class="blueSquare qAnswer">C</div>
  41. </td>
  42. <td style="vertical-align: middle;">
  43. <div class="qAnswer">ccc</div>
  44. </td>


zapłace ejot2@op.pl

Proszę o pomoc ejot2@op.pl zapłace za gotowy skrypt.
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 Aktualny czas: 21.08.2025 - 18:22