class Crawler extends SplObjectStorage
Crawler eases navigation of a list of \DOMNode objects.
Methods
|
__construct(mixed $node = null, string $uri = null)
Constructor. |
||
|
clear()
Removes all the nodes. |
||
|
add(null|DOMNodeList|array|DOMNode $node)
Adds a node to the current list of nodes. |
||
| null|void |
addContent(string $content, null|string $type = null)
Adds HTML/XML content. |
|
|
addHtmlContent(string $content, string $charset = 'UTF-8')
Adds an HTML content to the list of nodes. |
||
|
addXmlContent(string $content, string $charset = 'UTF-8')
Adds an XML content to the list of nodes. |
||
|
addDocument(DOMDocument $dom)
Adds a \DOMDocument to the list of nodes. |
||
|
addNodeList(DOMNodeList $nodes)
Adds a \DOMNodeList to the list of nodes. |
||
|
addNodes(array $nodes)
Adds an array of \DOMNode instances to the list of nodes. |
||
|
addNode(DOMNode $node)
Adds a \DOMNode instance to the list of nodes. |
||
| Crawler |
eq(integer $position)
Returns a node given its position in the node list. |
|
| array |
each(Closure $closure)
Calls an anonymous function on each node of the list. |
|
| Crawler |
reduce(Closure $closure)
Reduces the list of nodes by calling an anonymous function. |
|
| Crawler |
first()
Returns the first node of the current selection |
|
| Crawler |
last()
Returns the last node of the current selection |
|
| Crawler |
siblings()
Returns the siblings nodes of the current selection |
|
| Crawler |
nextAll()
Returns the next siblings nodes of the current selection |
|
| Crawler |
previousAll()
Returns the previous sibling nodes of the current selection |
|
| Crawler |
parents()
Returns the parents nodes of the current selection |
|
| Crawler |
children()
Returns the children nodes of the current selection |
|
| string |
attr(string $attribute)
Returns the attribute value of the first node of the list. |
|
| string |
text()
Returns the node value of the first node of the list. |
|
| array |
extract(array $attributes)
Extracts information from the list of nodes. |
|
| Crawler |
filterXPath(string $xpath)
Filters the list of nodes with an XPath expression. |
|
| Crawler |
filter(string $selector)
Filters the list of nodes with a CSS selector. |
|
| Crawler |
selectLink(string $value)
Selects links by name or alt value for clickable images. |
|
| Crawler |
selectButton(string $value)
Selects a button by name or alt value for images. |
|
| Link |
link(string $method = 'get')
Returns a Link object for the first node in the list. |
|
| array |
links()
Returns an array of Link objects for the nodes in the list. |
|
| Form |
form(array $values = null, string $method = null)
Returns a Form object for the first node in the list. |
|
| static string |
xpathLiteral(string $s)
Converts string for XPath expressions. |
Details
at line 38
public
__construct(mixed $node = null, string $uri = null)
Constructor.
at line 50
public
clear()
Removes all the nodes.
at line 65
public
add(null|DOMNodeList|array|DOMNode $node)
Adds a node to the current list of nodes.
This method uses the appropriate specialized add*() method based
on the type of the argument.
at line 86
public null|void
addContent(string $content, null|string $type = null)
Adds HTML/XML content.
at line 120
public
addHtmlContent(string $content, string $charset = 'UTF-8')
Adds an HTML content to the list of nodes.
at line 143
public
addXmlContent(string $content, string $charset = 'UTF-8')
Adds an XML content to the list of nodes.
at line 160
public
addDocument(DOMDocument $dom)
Adds a \DOMDocument to the list of nodes.
at line 174
public
addNodeList(DOMNodeList $nodes)
Adds a \DOMNodeList to the list of nodes.
at line 188
public
addNodes(array $nodes)
Adds an array of \DOMNode instances to the list of nodes.
at line 202
public
addNode(DOMNode $node)
Adds a \DOMNode instance to the list of nodes.
at line 220
public Crawler
eq(integer $position)
Returns a node given its position in the node list.
at line 249
public array
each(Closure $closure)
Calls an anonymous function on each node of the list.
The anonymous function receives the position and the node as arguments.
Example:
$crawler->filter('h1')->each(function ($node, $i)
{
return $node->nodeValue;
});
at line 270
public Crawler
reduce(Closure $closure)
Reduces the list of nodes by calling an anonymous function.
To remove a node from the list, the anonymous function must return false.
at line 289
public Crawler
first()
Returns the first node of the current selection
at line 301
public Crawler
last()
Returns the last node of the current selection
at line 315
public Crawler
siblings()
Returns the siblings nodes of the current selection
at line 333
public Crawler
nextAll()
Returns the next siblings nodes of the current selection
at line 349
public Crawler
previousAll()
Returns the previous sibling nodes of the current selection
at line 367
public Crawler
parents()
Returns the parents nodes of the current selection
at line 394
public Crawler
children()
Returns the children nodes of the current selection
at line 414
public string
attr(string $attribute)
Returns the attribute value of the first node of the list.
at line 432
public string
text()
Returns the node value of the first node of the list.
at line 456
public array
extract(array $attributes)
Extracts information from the list of nodes.
You can extract attributes or/and the node value (_text).
Example:
$crawler->filter('h1 a')->extract(array('_text', 'href'));
at line 486
public Crawler
filterXPath(string $xpath)
Filters the list of nodes with an XPath expression.
at line 512
public Crawler
filter(string $selector)
Filters the list of nodes with a CSS selector.
This method only works if you have installed the CssSelector Symfony Component.
at line 532
public Crawler
selectLink(string $value)
Selects links by name or alt value for clickable images.
at line 549
public Crawler
selectButton(string $value)
Selects a button by name or alt value for images.
at line 569
public Link
link(string $method = 'get')
Returns a Link object for the first node in the list.
at line 587
public array
links()
Returns an array of Link objects for the nodes in the list.
at line 609
public Form
form(array $values = null, string $method = null)
Returns a Form object for the first node in the list.
at line 646
static public string
xpathLiteral(string $s)
Converts string for XPath expressions.
Escaped characters are: quotes (") and apostrophe (').
Examples:
<code>
echo Crawler::xpathLiteral('foo " bar');
//prints 'foo " bar'
echo Crawler::xpathLiteral("foo ' bar");
//prints "foo ' bar"
echo Crawler::xpathLiteral('a\'b"c');
//prints concat('a', "'", 'b"c')
</code>