예제 #1
0
파일: wc.php 프로젝트: bala345/CodeSamples
    {
        return file_get_contents($uri);
    }
    public function get($type)
    {
        $method = "_get_{$type}";
        if (method_exists($this, $method)) {
            return call_user_method($method, $this);
        }
    }
    protected function _get_images()
    {
        if (!empty($this->markup)) {
            preg_match_all('/<img([^>]+)\\/>/i', $this->markup, $images);
            return !empty($images[1]) ? $images[1] : FALSE;
        }
    }
    protected function _get_links()
    {
        if (!empty($this->markup)) {
            preg_match_all('/<a([^>]+)\\>(.*?)\\<\\/a\\>/i', $this->markup, $links);
            return !empty($links[1]) ? $links[1] : FALSE;
        }
    }
}
$crawl = new Crawler('http://www.cricinfo.com/ci/content/current/match/fixtures/index.html');
$images = $crawl->get('images');
$links = $crawl->get('links');
foreach ($links as $value) {
    print $value . "\n";
}
예제 #2
0
<?php

include_once "Crawler.class.php";
$LEVELS = 1;
//how many levels deep do you want to Crawl?
//CRAWL the page specified by url and look for all images or links
if (empty($_REQUEST['url']) || $_REQUEST['url'] == " ") {
    $url = "http://bcmoney-mobiletv.com";
} else {
    $url = $_REQUEST['url'];
}
$crawl = new Crawler($url, $LEVELS);
$images = $crawl->get('images');
$links = $crawl->get('links');
$embeds = $crawl->get('embeds');
//DEBUG (print parsed values)
echo "<a href=\"{$url}\" target=\"_blank\">{$url}</a>";
echo "<br/><br/>IMAGES: <pre>";
print_r($images);
echo "</pre><br/>LINKS: <pre>";
print_r($links);
echo "</pre><br/>EMBEDS: <pre>";
print_r($embeds);
echo "</pre>";
/*
foreach ($images as $image) { ; }
foreach ($links as $link) { ; }
foreach ($embeds as $embed) { ; }
*/