Skip to content

Commit 44b6857

Browse files
committed
Added guzzle and loadFromUrl option
1 parent 55aa4ec commit 44b6857

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
],
1616
"require": {
1717
"php": ">=5.4",
18-
"paquettg/string-encode": "0.1.0"
18+
"paquettg/string-encode": "0.1.0",
19+
"guzzle/guzzle": "v3.8.0"
1920
},
2021
"require-dev": {
2122
"phpunit/phpunit": "3.7.*"

src/PHPHtmlParser/Dom.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
2+
23
namespace PHPHtmlParser;
34

5+
use Guzzle\Http\Client;
46
use PHPHtmlParser\Dom\HtmlNode;
57
use PHPHtmlParser\Dom\TextNode;
68

@@ -118,6 +120,21 @@ public function loadFromFile($file)
118120
return $this->load($document);
119121
}
120122

123+
/**
124+
* Uses guzzle to load the html from the given url.
125+
*
126+
* @param string $url
127+
* @chainable
128+
*/
129+
public function loadFromUrl($url)
130+
{
131+
$client = new Client($url);
132+
$response = $client->get()->send();
133+
$content = (string) $response;
134+
135+
return $this->load($content);
136+
}
137+
121138
/**
122139
* Find elements by css selector on the root node.
123140
*

0 commit comments

Comments
 (0)