Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新我的代码以清除需要cookie的站点_Php_Cookies_Scrape - Fatal编程技术网

Php 更新我的代码以清除需要cookie的站点

Php 更新我的代码以清除需要cookie的站点,php,cookies,scrape,Php,Cookies,Scrape,我正在使用这段代码来抓取页面名称、url和图像 它工作得很好,但是在一些网站上它失败了,并返回文本说需要cookies。如何设置cookie,或在访问URL/数据时模拟cookie <?php $url = $_REQUEST['url']; $url = checkValues($url); function checkValues($value) { $value = trim($value); if (get

我正在使用这段代码来抓取页面名称、url和图像

它工作得很好,但是在一些网站上它失败了,并返回文本说需要cookies。如何设置cookie,或在访问URL/数据时模拟cookie

    <?php

    $url = $_REQUEST['url'];
    $url = checkValues($url);

    function checkValues($value)
    {
        $value = trim($value);
        if (get_magic_quotes_gpc()) 
        {
            $value = stripslashes($value);
        }
        $value = strtr($value, array_flip(get_html_translation_table(HTML_ENTITIES)));
        $value = strip_tags($value);
        $value = htmlspecialchars($value);
        return $value;
    }   

    function fetch_record($path)
    {
        $file = fopen($path, "r"); 
        if (!$file)
        {
            exit("Problem occured");
        } 
        $data = '';
        while (!feof($file))
        {
            $data .= fgets($file, 1024);
        }
        return $data;
    }

    $string = fetch_record($url);


    /// fecth title
    $title_regex = "/<title>(.+)<\/title>/i";
    preg_match_all($title_regex, $string, $title, PREG_PATTERN_ORDER);
    $url_title = $title[1];

    /// fecth decription
    $tags = get_meta_tags($url);

    // fetch images
    $image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
    preg_match_all($image_regex, $string, $img, PREG_PATTERN_ORDER);
    $images_array = $img[1];

    ?>

        <div class="images">
        <?php
        $k=1;
        for ($i=0;$i<=sizeof($images_array);$i++)
        {
            if(@$images_array[$i])
            {
                if(@getimagesize(@$images_array[$i]))
                {
                    list($width, $height, $type, $attr) = getimagesize(@$images_array[$i]);
                    if($width >= 50 && $height >= 50 ){

                    echo "<img src='".@$images_array[$i]."' width='100' id='".$k."' >";

                    $k++;

                    }
                }
            }
        }
        ?>
        <!--<img src="ajax.jpg"  alt="" />-->
        <input type="hidden" name="total_images" id="total_images" value="<?php echo --$k?>" />
        </div>
        <div class="info">

            <label class="title">
                <?php  echo @$url_title[0]; ?>
            </label>
            <br clear="all" />
            <label class="url">
                <?php  echo substr($url ,0,35); ?>
            </label>
            <br clear="all" /><br clear="all" />
            <label class="desc">
                <?php  echo @$tags['description']; ?>
            </label>
            <br clear="all" /><br clear="all" />

            <label style="float:left"><img src="prev.png" id="prev" alt="" /><img src="next.png" id="next" alt="" /></label>

            <label class="totalimg">
                Total <?php echo $k?> images
            </label>
            <br clear="all" />

        </div>

除非您使用的是旧的PHP版本(低于5.3),否则不应该使用
get\u magic\u quotes\u gpc
magic\u quotes\u gpc
was(
get\u magic\u quotes\u gpc
in PHP>=5.3.0)谢谢。这会解决问题吗,还是对代码进行额外的分析?只是观察,这不会解决问题。但是保持代码干净总是更好的——这样就不会出现错误:)