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:
<?php
###########################################################
/*
GuestBook Script
Copyright (C) StivaSoft ltd. All rights Reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
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>.
For further information visit:
<a href="http://www.phpjabbers.com/" target="_blank">http://www.phpjabbers.com/</a>
info@phpjabbers.com
Version: 1.0
Released: 2014-11-25
*/
###########################################################
include("config.php");
include("./simple_html_dom");
?>
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Logowanie</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="css/main.css">
<link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500' rel='stylesheet' type='text/css'>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<?php
$error = '';
if(isset($_POST['is_login'])){ $sql_result = mysql_query ($sql, $connection ) or
die ('request "Could not execute SQL query" '.$sql); $_SESSION['user_info'] = $user;
$query = " UPDATE ".$SETTINGS["USERS"]." SET last_login = NOW() WHERE id=".$user['id'];
mysql_query ($query, $connection ) or
die ('request "Could not execute SQL query" '.$query); }
else{
$error = 'Wrong email or password.';
}
}
if(isset($_GET['ac']) && $_GET['ac'] == 'logout'){ $_SESSION['user_info'] = null;
unset($_SESSION['user_info']); }
?>
<?php if(isset($_SESSION['user_info']) && is_array($_SESSION['user_info'])) { ?>
<form id="login-form" class="login-form" name="form1">
<div id="form-content">
<div class="welcome">
<?php echo $_SESSION['user_info']['name'] ?>, jestes zalogowany.
<br/>Wklej adres URL do odpowiedniej linijki i zatwierdz przyciskiem obok dla danej platformy<br/>
<form method="get">
<input type="text" name="link1"/>
<input type="submit" name="submit1" value="allegro"/>
</form>
<form method="get">
<input type="text" name="link2"/>
<input type="submit" name="submit2" value="olx"/>
</form>
<form method="get">
<input type="text" name="link3"/>
<input type="submit" name="submit3" value="otomoto"/>
</form>
<a href="index.php?ac=logout" style="color:#3ec038">Wyloguj</a>
</div>
</div>
<?
if(isset($_GET["submit1"])) {
$link1=$_GET["link1"];
$html = file_get_html('.$link1.');
echo $html->find(".price", 0
)->innertext; }
if(isset($_GET["submit2"])) {
$link2=$_GET["link2"];
}
if(isset($_GET["submit3"])) {
$link3=$_GET["link3"];
}
?>
</form>
<?php } else { ?>
<form id="login-form" class="login-form" name="form1" method="post" action="index.php">
<input type="hidden" name="is_login" value="1">
<div class="h1">Logowanie</div>
<div id="form-content">
<div class="group">
<label for="email">Email</label>
<div><input id="email" name="email" class="form-control required" type="email" placeholder="Email"></div>
</div>
<div class="group">
<label for="name">Haslo</label>
<div><input id="password" name="password" class="form-control required" type="password" placeholder="Password"></div>
</div>
<?php if($error) { ?>
<em>
<label class="err" for="password" generated="true" style="display: block;">
<?php echo $error ?></label>
</em>
<?php } ?>
<div class="group submit">
<label class="empty"></label>
<div><input name="submit" type="submit" value="Submit"/></div><br></br>
<a href="../index.php">Wroc na strone glowna</a>
</div>
</div>
<div id="form-loading" class="hide"><i class="fa fa-circle-o-notch fa-spin"></i></div>
</form>
<?php } ?>
</body>
</html>
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:
[b
] if(isset($_GET["submit1"])) {
$link1=$_GET["link1"];
$html = file_get_html('.$link1.');
echo $html->find(".price", 0
)->innertext; }[/b]
Chcialbym, zebrac takze takie dane jak: rok, przebieg, pojemnosc silnika, moc i adres url zdjecia glownego.
rok, przebieg, pojemnosc i moc:
<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:
<a href="#imglayer"> <noscript class="lazyGallery"> <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"
> </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.