本文整理汇总了PHP中Crawler::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::get方法的具体用法?PHP Crawler::get怎么用?PHP Crawler::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crawler
的用法示例。
在下文中一共展示了Crawler::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
{
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: Crawler
<?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) { ; }
*/