Ejemplo n.º 1
0
 public function testBuildPage()
 {
     $url = 'http://www.google.com/';
     $client = new Client(array('url' => $url, 'data_config' => array('test' => '//h1[@id="test-heading"]'), 'builder' => new PageBuilderStub()));
     $page = $client->fetchPage();
     $data = $page->getData();
     $this->assertInstanceOf('PageScraper\\Page\\PageInterface', $page);
     $this->assertEquals($url, $page->getUrl());
     $this->assertEquals('Testing H1', $data['test']);
     $this->assertInstanceOf('PageScraper\\Tests\\Stub\\PageBuilder', $client->getBuilder());
 }
Ejemplo n.º 2
0
<?php

libxml_use_internal_errors(true);
include __DIR__ . '/../vendor/autoload.php';
use PageScraper\Client;
// the most simpliest way to fetch the data is to use the Client
$client = new Client(array('url' => 'https://news.ycombinator.com', 'data_config' => array('titles' => '//td[@class="title"]//a/text()', 'links' => '//td[@class="title"]//a/@href', 'side_links' => array('css' => '.title .comhead'))));
// fetch the data, and get the Page object
$page = $client->fetchPage();
// get the desired data
$data = $page->getData();
// print the data
echo '<pre>';
print_r($data);
echo '</pre>';