fiv/parser

This package is abandoned and no longer maintained. The author suggests using the xparse/parser package instead.

Parser bundle

2.0.3 2014-11-28 09:23 UTC

README

Flexible way for data scraping

Build Status GitHub version

Installation

composer require fiv/parser:2.0.*

Fetch all href attributes

 $grabber = new \Fiv\Parser\Grabber();
 $links = $grabber->getHtml('http://funivan.com')->attribute('//a/@href')->getItems();
 
 print_r($links);
 

Submit form

 $grabber = new \Fiv\Parser\Grabber();
 $page = $grabber->getHtml('http://funivan.com/admin/');
 
 $formData = array('name' => 'admin');
 $adminPage = $grabber->submitForm($formData, '//form[@id="login"]');
 
 $logoutLink = $adminPage->attribute('//a[@id="logout"]/@href')->getFirst();
 echo $logoutLink;
  

Get page status

  $request = new \Fiv\Parser\Request();
  $request->get('http://funivan.com');
  $httpCode = $request->getInfo()->getHttpCode();
  echo $httpCode;

Get page and store in local cache

  $request = new \Fiv\Parser\Request();
  $request->setCacheAdapter(new \Fiv\Parser\Cache\FileCache());

  
  # real request to server
  $page = $request->get("http://funivan.com/");

  # get from cache
  $cachePage = $request->get("http://funivan.com/");