Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Simple_html_dom i allegro
Forum PHP.pl > Forum > Przedszkole
Robsonkox
Witam, znalazlem potrzebny mi parser o nazwie Simple_html_dom i chcialem go podpiac, aby zebral kilka danych z allegro.pl/jakiestamogloszenie i tu mam problem.
Mam strone z logowaniem(ktora dostepna bedzie tylko dla mnie) i w niej kod:

  1. <?php
  2. ###########################################################
  3. /*
  4. GuestBook Script
  5. Copyright (C) StivaSoft ltd. All rights Reserved.
  6.  
  7.  
  8. This program is free software: you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation, either version 3 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see <a href="http://www.gnu.org/licenses/gpl-3.0.html" target="_blank">http://www.gnu.org/licenses/gpl-3.0.html</a>.
  20.  
  21. For further information visit:
  22. <a href="http://www.phpjabbers.com/" target="_blank">http://www.phpjabbers.com/</a>
  23. info@phpjabbers.com
  24.  
  25. Version: 1.0
  26. Released: 2014-11-25
  27. */
  28. ###########################################################
  29.  
  30. session_name('LoginForm');
  31.  
  32. include("config.php");
  33. include("./simple_html_dom");
  34.  
  35. ?>
  36. <!DOCTYPE html>
  37. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
  38. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
  39. <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
  40. <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  41. <head>
  42. <meta charset="utf-8">
  43. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  44. <title>Logowanie</title>
  45. <meta name="description" content="">
  46. <meta name="viewport" content="width=device-width, initial-scale=1">
  47.  
  48. <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
  49.  
  50. <link rel="stylesheet" href="css/main.css">
  51. <link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500' rel='stylesheet' type='text/css'>
  52. <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
  53. <script src="js/jquery-1.8.2.min.js"></script>
  54. <script src="js/jquery.validate.min.js"></script>
  55. <script src="js/main.js"></script>
  56. </head>
  57. <body>
  58. <?php
  59. $error = '';
  60. if(isset($_POST['is_login'])){
  61. $sql = "SELECT * FROM ".$SETTINGS["USERS"]." WHERE `email` = '".mysql_real_escape_string($_POST['email'])."' AND `password` = '".mysql_real_escape_string($_POST['password'])."'";
  62. $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
  63. $user = mysql_fetch_assoc($sql_result);
  64. if(!empty($user)){
  65. $_SESSION['user_info'] = $user;
  66. $query = " UPDATE ".$SETTINGS["USERS"]." SET last_login = NOW() WHERE id=".$user['id'];
  67. mysql_query ($query, $connection ) or die ('request "Could not execute SQL query" '.$query);
  68. }
  69. else{
  70. $error = 'Wrong email or password.';
  71. }
  72. }
  73.  
  74. if(isset($_GET['ac']) && $_GET['ac'] == 'logout'){
  75. $_SESSION['user_info'] = null;
  76. unset($_SESSION['user_info']);
  77. }
  78. ?>
  79. <?php if(isset($_SESSION['user_info']) && is_array($_SESSION['user_info'])) { ?>
  80.  
  81. <form id="login-form" class="login-form" name="form1">
  82.  
  83. <div id="form-content">
  84. <div class="welcome">
  85. <?php echo $_SESSION['user_info']['name'] ?>, jestes zalogowany.
  86. <br/>Wklej adres URL do odpowiedniej linijki i zatwierdz przyciskiem obok dla danej platformy<br/>
  87. <form method="get">
  88. <input type="text" name="link1"/>
  89. <input type="submit" name="submit1" value="allegro"/>
  90. </form>
  91. <form method="get">
  92. <input type="text" name="link2"/>
  93. <input type="submit" name="submit2" value="olx"/>
  94. </form>
  95. <form method="get">
  96. <input type="text" name="link3"/>
  97. <input type="submit" name="submit3" value="otomoto"/>
  98. </form>
  99. <a href="index.php?ac=logout" style="color:#3ec038">Wyloguj</a>
  100. </div>
  101. </div>
  102.  
  103.  
  104. <?
  105. if(isset($_GET["submit1"]))
  106. {
  107. $link1=$_GET["link1"];
  108. $html = file_get_html('.$link1.');
  109. echo $html->find(".price", 0)->innertext;
  110. }
  111. if(isset($_GET["submit2"]))
  112. {
  113. $link2=$_GET["link2"];
  114. }
  115. if(isset($_GET["submit3"]))
  116. {
  117. $link3=$_GET["link3"];
  118. }
  119. ?>
  120. </form>
  121. <?php } else { ?>
  122. <form id="login-form" class="login-form" name="form1" method="post" action="index.php">
  123. <input type="hidden" name="is_login" value="1">
  124. <div class="h1">Logowanie</div>
  125. <div id="form-content">
  126. <div class="group">
  127. <label for="email">Email</label>
  128. <div><input id="email" name="email" class="form-control required" type="email" placeholder="Email"></div>
  129. </div>
  130. <div class="group">
  131. <label for="name">Haslo</label>
  132. <div><input id="password" name="password" class="form-control required" type="password" placeholder="Password"></div>
  133. </div>
  134. <?php if($error) { ?>
  135. <em>
  136. <label class="err" for="password" generated="true" style="display: block;"><?php echo $error ?></label>
  137. </em>
  138. <?php } ?>
  139. <div class="group submit">
  140. <label class="empty"></label>
  141. <div><input name="submit" type="submit" value="Submit"/></div><br></br>
  142. <a href="../index.php">Wroc na strone glowna</a>
  143. </div>
  144. </div>
  145. <div id="form-loading" class="hide"><i class="fa fa-circle-o-notch fa-spin"></i></div>
  146. </form>
  147. <?php } ?>
  148. </body>
  149. </html>
  150.  


Kod odpowiadajacy za otrzymanie linku i prace z nim jest pogrubiony.
Szukalem na internecie rozwiazania, niestety bardzo malo jest tutoriali do tego parsera(a ja jestem laikiem i raczej tego sam nie ogarne mimo szczerych checi i wielu prob) tak wiec allegro mam np cene z ogloszenia:

<div class="inline"> <div class="above">cena kup teraz</div> <div class="price" data-price="100.0">100,00 zł</div> <link itemprop="availability" href="http://schema.org/InStock"> </div>

kod:
  1. [b] if(isset($_GET["submit1"]))
  2. {
  3. $link1=$_GET["link1"];
  4. $html = file_get_html('.$link1.');
  5. echo $html->find(".price", 0)->innertext;
  6. }[/b]


Chcialbym, zebrac takze takie dane jak: rok, przebieg, pojemnosc silnika, moc i adres url zdjecia glownego.

rok, przebieg, pojemnosc i moc:

  1. <div class="attributes-container"> <ul class="list-unstyled offer-attributes offer-single-attributes"> <li> <span class="attribute-name">stan:</span> <span class="attribute-value">używany</span> </li> <li> <span class="attribute-name">rok produkcji:</span> <span class="attribute-value">1998</span> </li> <li> <span class="attribute-name">przebieg [km]:</span> <span class="attribute-value">326987</span> </li> <li> <span class="attribute-name">pojemność silnika [cm3]:</span> <span class="attribute-value">4398</span> </li> <li> <span class="attribute-name">moc [KM]:</span> <span class="attribute-value">286</span> </li> <li> <span class="attribute-name">rodzaj paliwa:</span> <span class="attribute-value">benzyna</span> </li> <li> <span class="attribute-name">nadwozie:</span> <span class="attribute-value">kombi</span> </li> <li> <span class="attribute-name">liczba drzwi:</span> <span class="attribute-value">4/5</span> </li> <li> <span class="attribute-name">liczba miejsc:</span> <span class="attribute-value">5</span> </li> </ul> <ul class="list-unstyled offer-attributes offer-single-attributes"> <li> <span class="attribute-name">skrzynia biegów:</span> <span class="attribute-value">automatyczna hydrauliczna (klasyczna)</span> </li> <li> <span class="attribute-name">napęd:</span> <span class="attribute-value">4x4 (stały)</span> </li> <li> <span class="attribute-name">kolor:</span> <span class="attribute-value">zielony</span> </li> <li> <span class="attribute-name">lakier:</span> <span class="attribute-value">metalik</span> </li> <li> <span class="attribute-name">kierownica po prawej (Anglik):</span> <span class="attribute-value">nie</span> </li> <li> <span class="attribute-name">uszkodzony:</span> <span class="attribute-value">nie</span> </li> <li> <span class="attribute-name">kraj pochodzenia:</span> <span class="attribute-value">Szwajcaria</span> </li> <li> <span class="attribute-name">informacje dodatkowe:</span> <span class="attribute-value">serwisowany w ASO</span> </li> </ul>


oraz url zdjecia glownego:

  1. <a href="#imglayer"> <noscript class="lazyGallery"> &lt;img src="https://d.allegroimg.com/s400/01b8c6/05c1f8b5452487ad18ab9e0be75d" class="img-responsive" data-img-large="https://d.allegroimg.com/original/01b8c6/05c1f8b5452487ad18ab9e0be75d" data-img-medium="https://d.allegroimg.com/s400/01b8c6/05c1f8b5452487ad18ab9e0be75d" data-img-id="1" alt="BMW 540i E39 TOURING NAVI SKÓRA VOLL SZWAJCARIA"&gt; </noscript><img src="https://d.allegroimg.com/s400/01b8c6/05c1f8b5452487ad18ab9e0be75d" class="img-responsive" data-img-large="https://d.allegroimg.com/original/01b8c6/05c1f8b5452487ad18ab9e0be75d" data-img-medium="https://d.allegroimg.com/s400/01b8c6/05c1f8b5452487ad18ab9e0be75d" data-img-id="1" alt="BMW 540i E39 TOURING NAVI SKÓRA VOLL SZWAJCARIA"> </a>


Bede wdzieczny za kazda wskazowke jak i pomoc. Dzieki.
viking
To są raczej podstawy CSS. Możesz wykorzystać np nth-child. Natomiast prawidłowym sposobem pobierania tych danych jest http://allegro.pl/webapi
Robsonkox
Nie chcialbym korzystac z api allegro, gdyz ciezko mi jest to ogarnac a co dopiero podstawiac jeszcze wszystko od allegro...

Dziwi mnie dlaczego, ten fragment kodu nic nie pobiera...

  1. $link1=$_GET["link1"];
  2. $html = file_get_html('.$link1.');
  3. echo $html->find(".attributes-container ul. list-unstyled offer-attributes offer-single-attributes li:nth-child(2) span.attribute-value")->innertext;


Podalem w tym wszystkie dane i dalej nic nie pokazuje...
nospor
$html = file_get_html('.$link1.');
Czyli dziwi cie, czemu to nie dziala? Hm.... pomyslmy.....

echo '.$link1.';
Co widzisz na ekranie?


echo $link1;
A teraz co widzisz na ekranie?

Przenosze
Robsonkox
O kurde, a ja durny szukalem kombinowalem... Dzieki wielkie naprawde. oneeyedsmiley02.png oneeyedsmiley02.png oneeyedsmiley02.png oneeyedsmiley02.png Nie wiem jak ja tego nie zauwazylem.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.