asymptix / php-html-dom-parser
Composer adaptation and wrapper for the Simple HTML DOM parser written on PHP5+ let you manipulate HTML in a very easy and fast way. It supports invalid HTML DOM and may find tags in HTML DOM with selectors just like jQuery.
Installs: 3 081
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Language:HTML
Requires
- php: >=5.3.2
This package is not auto-updated.
Last update: 2024-11-09 18:38:14 UTC
README
Composer adaptation and wrapper for the Simple HTML DOM parser written on PHP5+ let you manipulate HTML in a very easy and fast way. It supports invalid HTML DOM and may find tags in HTML DOM with selectors just like jQuery.
Composer installation
To install with Composer simply create this composer.json
file in your project root folder and run composer command composer install
.
{ "minimum-stability": "dev", "require": { "php": ">=5.3.2", "asymptix/php-html-dom-parser": "1.5.*" } }
Usage
Here you can find a simple example how to use Parser to parse products from some shop web-site and then parse product details from product pages:
use Asymptix\HtmlDomParser\HtmlDomParser; require_once('vendor/autoload.php'); $url = "http://www.some-shop.com/"; $html = new HtmlDomParser(); $html->loadUrl($url); foreach ($html->find("a.product") as $productItem) { $productHtml = new HtmlDomParser(); $productHtml->loadUrl($productItem->href); $productDetails = $productHtml->find("div#productDetails", 0); $productForm = $productHtml->find("div#productForm", 0); $product = new stdClass(); if (is_object($productForm)) { $product->price = $productForm->find("div.price", 0)->plaintext; } unset($productHtml); }
Copyright (c) 2012 S.C. Chen, John Schlick, Rus Carroll from the Simple HTML DOM lib developers team.
Copyright (c) 2015 Asymptix.