haffoudhi / simplehtmldom
Simple html dom 作为 silex 服务
dev-master / 1.0.x-dev
2014-05-09 16:21 UTC
Requires
- silex/silex: ~1.2
This package is not auto-updated.
Last update: 2024-09-10 07:03:56 UTC
README
这是一个简单的 silex 服务,它将 simple html dom 集成到 silex 作为一项服务。
安装说明
Via Composer :
1 - Add this line to composer file: "haffoudhi/simplehtmldom": "@dev"
2 - Then run composer update.
3 - Register the new service in your bootstrap file $app->register(new Haffoudhi\Silex\SimpleHtmlDomServiceProvider());
Without Composer :
1 - Copy the folder Haffoudhi under the src file of your silex project.
2 - Register the new service in your bootstrap file $app->register(new Haffoudhi\Silex\SimpleHtmlDomServiceProvider());
如何使用
现在,在你成功安装了该服务后,在你的控制器中,
1 - call the service : $simpleHtmlDom = $app['simpleHtmlDom'];
2 - Use simplehtmldom to get all the links from a string :
$content = file_get_contents(__DIR__ . '/anyWebPage.htm'); // $content can be the
//result of curl function or the content of html file, it's a string that contains the html source
$simpleHtmlDom->load($content);
// Find all links
foreach($simpleHtmlDom->find('a') as $element) {
echo $element->href . '<br/>';
}
3 - Use simplehtmldom to get all the links from a file :
$simpleHtmlDom->load_file(__DIR__ . '/anyWebPage.htm'); // we introduce the path to the file
//that contains the html source
// Find all links
foreach($simpleHtmlDom->find('a') as $element) {
echo $element->href . '<br/>';
}
最后提醒,
1 - Need some assistance in data scraping, web scraping using silex and simple_html_dom
2 - You do have some problems implementing the service
然后提出新的请求,我会尽快回答。