Shoora
1/14/2014 - 12:15 PM

Parse HTML via phpQuery example

Parse HTML via phpQuery example

<?php

include_once( "libs/phpQuery/phpQuery.php" );

$content = file_get_contents( '2.html' ); // 2.html is HTML content
$content = phpQuery::newDocument( $content );
$content = pq( $content )->find( 'div.js-metrika-offers-count' );

$result  = array();
$counter = 0;

foreach ( pq( 'div.b-offers' ) as $offer )
{
	$o                                = pq( $offer );
	$result[ $counter ][ 'shop' ]     = $o->find( '.b-offers__feats>a.shop-link:first' )->text();
	$result[ $counter ][ 'price' ]    = preg_replace( "/[^0-9]/", "", $o->find( 'b.b-prices__i>span.b-prices__num' )->html() );
	$result[ $counter ][ 'dostavka' ] = preg_replace( "/[^0-9]/", "", $o->find( 'div.b-offers__delivery' )->find( 'span.b-more__text' )->remove()->end()->text() );
	$result[ $counter ][ 'rating' ]   = $o->find( '.b-offers__feats' )->find( '.b-rating__star-other' )->length;
	$result[ $counter++ ][ 'status' ] = $o->find( 'div.b-offers__price>div.b-offers__onstock>b:first' )->text();
}

echo '<pre>' . print_r( $result, true ) . '</pre>';