无法使用php从其他网站抓取

时间:2019-06-07 12:48:20

标签: php curl

我想从网站上抓取。该代码以前运行良好。但是突然代码无法正常工作,并显示空白屏幕。它会从gettrends网站收集标签,并检查是否已在数据库中添加该标签,例如是否已在数据库中添加该标签,然后再添加到表标签中。

问题出在哪里?

<?php
    set_time_limit(0);

    include ('../includes/settings.php');

    $curl=curl_init();

    curl_setopt($curl, CURLOPT_URL, 'https://getdaytrends.com/tr/germany/');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $data = curl_exec($curl);
    $ulkegenel=explode('<ul class="country-list" id="places">',$data);
    $ulkegenel=explode('</ul>',$ulkegenel[1]);
    $ulkesay=explode('<a href="',$ulkegenel[0]);
    $ulkesaydim=count($ulkesay)-2;

    for($a=1;$a<=$ulkesaydim;$a++)
    {
        $ulkegetir=explode('<a href="',$ulkgenel[0]);
        $ulkegetir=explode('"',$ulkegetir[$a]);
        $curl2=curl_init();

        curl_setopt($curl2, CURLOPT_URL, 'https://getdaytrends.com/tr'.$ulkegetir[0].'/');
        curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);

        $data2 = curl_exec($curl2);
        print_r($data2);

        $genel=explode('<tbody id="table-body">',$data2);
        $genel=explode('</tbody>',$genel[1]);
        $etiketsay=explode('target="twitter">',$genel[0]);
        $saydim=count($etiketsay)-1;

        for($i=1;$i<=$saydim;$i++)
        {
            $etiketgetir=explode('target="twitter">',$genel[0]);
            $etiketgetir=explode('<',$etiketgetir[$i]);
            $etiketgetir[0]=str_replace('#', '', $etiketgetir[0]);
            $link='https://website.com/tag/'.seo($etiketgetir[0]);
            $sorgula=mysql_num_rows(mysql_query("SELECT * FROM table001 WHERE link='".$link."' LIMIT 1"));

            if($sorgula==0) {
                echo 'https://website.com/'.seo($etiketgetir[0]).'-----  Added <br /> ' ;
                $ekle=mysql_unbuffered_query("INSERT INTO table001 SET link='".$link."'");
            } else {
                echo 'https://website.com/'.seo($etiketgetir[0]).'-----  Has Added <br /> ' ;
            }

        }
    }
?>

0 个答案:

没有答案