• 10-03-2017, 17:22:08
    #1
    http://www.guide34.com/Elektrik-&-El...F/8-175-0.html


    bu site üzerinde buluna firma adı ve telefon numaralarını çekmek istiyorum isimleri çekmeyi yaptım ama telefon numaralarınıda çekme konusunda birşey gelmedi elimden yardımıcı olurmusnuz.


    Bot.php

    <?php
    
    @header('Content-Type: text/html; charset=utf-8');
    @ini_set('default_charset', 'utf-8');
    @mb_internal_encoding('utf-8');
    @mb_detect_order('utf-8');
    
    function dizi_goster($veri){
        echo "<pre>";
        print_r($veri);
        echo "</pre>";
    }
    
    function Bot($url) {
        $ac = Curl($url);
    
        @preg_match_all('#<tr>(.*?)</tr>#si',$ac,$link);
    
    
        foreach ($link[1] as $ln) {
    
            @preg_match('#<span class="companyA">(.*?)</span>#si',$ln,$alan);
            if( strlen(@$alan[1]) > 0 ) {
                echo $alan[1]. "<br>";
    
            }
    
    
        }
    
    
    }
    function Curl($url, $proxy = NULL) {
        $options = array(
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => 1,
            CURLOPT_HEADER => false,
            CURLOPT_ENCODING => "",
            CURLOPT_AUTOREFERER => true,
            CURLOPT_CONNECTTIMEOUT => 30,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false
        );
        $ch = curl_init($url);
        curl_setopt_array($ch, $options);
        $content = curl_exec($ch);
        $err = curl_errno($ch);
        $errmsg = curl_error($ch);
        $header = curl_getinfo($ch);
        curl_close($ch);
        $header['errno'] = $err;
        $header['errmsg'] = $errmsg;
        $header['content'] = $content;
        return str_replace(array("\n", "\r", "\t"), NULL, $header['content']);
    }

    index.php

    <?php
    @header('Content-Type: text/html; charset=utf-8');
    @ini_set('default_charset', 'utf-8');
    @mb_internal_encoding('utf-8');
    @mb_detect_order('utf-8');
    
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <?php
    include 'bot.php';
    Bot("http://www.guide34.com/Elektrik-&-Elektronik/2.-El-Al%C4%B1%C5%9F-Sat%C4%B1%C5%9F/8-175-0.html");
    ?>
    </body>
    </html>
  • 17-03-2017, 15:53:28
    #2
    kimseden cevap gelmeyince ve uğraşınca oldu belki başkar arakadaşlara yardımı dokunur

    <?php
    
    
    header('Content-Type: text/html; charset=utf-8');
    
    function find_tag_content($start, $finish, $content)
    {
        @preg_match_all('/'.preg_quote($start, '/').'(.*?)'.preg_quote($finish, '/').'/i', $content, $m);
    
        return @$m[1];
    }
    function find_tag_content2($start, $finish, $content)
    {
        $first  = explode($start, $content);
        $result = explode($finish, $first[0]);
    
        return $result[0];
    }
    
    function replaceSpace($string)
    {
        $string = preg_replace("/\s+/", " ", $string);
        $string = trim($string);
        $string = str_replace('\n', " ", $string);
    
        return $string;
    }
    
    $data = array();
    $insertedIDs = array();
    if($_POST)
    {
        $host   = "localhost";
        $dbname = "botv1";
        $dbuser = "root";
        $dbpass = "";
        try
        {
            $db = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $dbuser, $dbpass);
    
            $table_exists = $db->query("SHOW TABLES LIKE 'firmalar';");
            if(!$table_exists)
            {
                die(print_r($dbh->errorInfo(), true));
            }
            if($table_exists->rowCount()==0)
            {
                $create_table_sql = "CREATE TABLE IF NOT EXISTS `firmalar` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `firma` varchar(255) NOT NULL,
      `telefon` mediumtext NOT NULL,
      `adres` varchar(255) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
                $db->exec($create_table_sql);
            }
        }
        catch(PDOException $e)
        {
            die($e->getMessage());
        }
    
        $link = $_POST["link"];
    
        $content = file_get_contents($link);
        $q       = explode('<td align="left" valign="center" width="60%" bgcolor="', $content);
        array_shift($q);
        $o = count($q);
        for($i = 0; $i<$o; $i++)
        {
            $ox                 = explode('</span>', $q[$i]);
            $ox                 = substr($ox[0], 11);
            $data[$i]["baslik"] = iconv('ISO-8859-9', 'UTF-8', strip_tags(replaceSpace($ox)));
        }
    
        $p = explode('<td align="left" valign="center" width="20%" bgcolor="', $content);
        array_shift($p);
        $s = count($p);
        $x = 0;
        for($i = 0; $i<$s; $i++)
        {
            if($i%2==0)
            {
                if($i!=0)
                {
                    $x++;
                }
                $tel = $p[$i];
                $tel = explode('" />', $tel);
                $tel = str_replace(","," ",replaceSpace($tel[1]));
    
                $telefonlar = array();
                $telExp = preg_split('/<br[^>]*>/i', $tel);
                foreach($telExp as $tel)
                {
                    $tel = trim(iconv('ISO-8859-9', 'UTF-8', strip_tags($tel)));
                    if(strstr($tel,"/"))
                    {
                        $telExp2 = explode("/",$tel);
                        foreach($telExp2 as $tel2)
                        {
                            $tel2 = trim($tel2);
                            if(!empty($tel2) && !strstr($tel2,"@"))
                                $telefonlar[] = $tel2;
                        }
                    }
                    else
                    {
                        if(strstr($tel,"---"))
                        {
                            $telExp3 = explode("---",$tel);
                            foreach($telExp3 as $tel3)
                            {
                                $tel3 = trim($tel3);
                                if(!empty($tel3) && !strstr($tel3,"@"))
                                    $telefonlar[] = $tel3;
                            }
                        }
                        elseif(!empty($tel))
                            $telefonlar[] = $tel;
                    }
                }
                $tel = json_encode($telefonlar);
    
                $data[$x]["tel"] = $tel;
            }
            else
            {
                $adres = $p[$i];
                $adres = explode("<a", $adres);
                $adres = substr($adres[0], 11);
                $adres = replaceSpace($adres);
    
                if($i==39)
                {
                    $adres = explode("<b>", $adres);
                    $adres = substr($adres[0], 0, -2);
                }
    
                $data[$x]["adres"] = iconv('ISO-8859-9', 'UTF-8', strip_tags($adres));
            }
        }
    
        if(!empty($data))
        {
            foreach($data as $satir)
            {
                $sql_data = array(
                    $satir["baslik"],
                    $satir["tel"],
                    $satir["adres"],
                );
    
                $insert = $db->prepare("INSERT INTO firmalar (firma,telefon,adres) VALUES (?,?,?)");
                if($insert->execute($sql_data))
                    $insertedIDs[] = $db->lastInsertId();
    
                $hata = $insert->errorInfo();
                if(!empty($hata[2]))
                {
                    echo $hata[2];
                    die();
                }
            }
        }
    }
    ?><!DOCTYPE html>
    <html>
    <head>
        <title>Bot v1</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
        <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class="container">
        <form action="" method="post" class="text-center" style="width:400px;margin:200px auto">
            <div class="form-group">
                <input type="text" name="link" class="form-control" value="" placeholder="Lütfen link giriniz" required> <input style="margin-top:20px;" type="submit" value="Verileri Çek ve Kaydet" class="btn btn-block btn-primary">
            </div>
        </form>
    
        <div class="">
            <?php if(!empty($data))
            { ?>
                <h3 class="text-center"> Sonuçlar : Veritabanına <?=count($insertedIDs)?> kayıt eklendi</h3>
                <table class="table table-striped">
                    <tr>
                        <th>#</th>
                        <th>Firma</th>
                        <th>Telefon</th>
                        <th>Adres</th>
                    </tr>
                    <?php foreach($data as $i => $row)
                    { ?>
                        <tr>
                            <td><?=++$i?></td>
                            <td><?=$row['baslik']?></td>
                            <td><?=$row['tel']?></td>
                            <td><?=$row['adres']?></td>
                        </tr>
                    <?php } ?>
                </table>
                <?php
            } ?>
        </div>
    </div>
    </body>
    </html>