PHP Класс Symfony\Component\DomCrawler\Crawler

Автор: Fabien Potencier ([email protected])
Наследование: extends SplObjectStorage
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$uri The current URI

Открытые методы

Метод Описание
__construct ( mixed $node = null, string $currentUri = null, string $baseHref = null )
add ( DOMNodeList | DOMNode | array | string | null $node ) Adds a node to the current list of nodes.
addContent ( string $content, null | string $type = null ) Adds HTML/XML content.
addDocument ( DOMDocument $dom ) Adds a \DOMDocument to the list of nodes.
addHtmlContent ( string $content, string $charset = 'UTF-8' ) Adds an HTML content to the list of nodes.
addNode ( DOMNode $node ) Adds a \DOMNode instance 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.
addXmlContent ( string $content, string $charset = 'UTF-8', integer $options = LIBXML_NONET ) Adds an XML content to the list of nodes.
attr ( string $attribute ) : string | null Returns the attribute value of the first node of the list.
children ( ) : Crawler Returns the children nodes of the current selection.
clear ( ) Removes all the nodes.
count ( ) : integer
each ( Closure $closure ) : array Calls an anonymous function on each node of the list.
eq ( integer $position ) : Crawler Returns a node given its position in the node list.
evaluate ( string $xpath ) : array | Crawler Evaluates an XPath expression.
extract ( array $attributes ) : array Extracts information from the list of nodes.
filter ( string $selector ) : Crawler Filters the list of nodes with a CSS selector.
filterXPath ( string $xpath ) : Crawler Filters the list of nodes with an XPath expression.
first ( ) : Crawler Returns the first node of the current selection.
form ( array $values = null, string $method = null ) : Form Returns a Form object for the first node in the list.
getBaseHref ( ) : string Returns base href.
getIterator ( ) : ArrayIterator
getNode ( integer $position ) : DOMElement | null
getUri ( ) : string Returns the current URI.
html ( ) : string Returns the first node of the list as HTML.
image ( ) : Symfony\Component\DomCrawler\Image Returns an Image object for the first node in the list.
images ( ) : Symfony\Component\DomCrawler\Image[] Returns an array of Image objects for the nodes in the list.
last ( ) : Crawler Returns the last node of the current selection.
link ( string $method = 'get' ) : Symfony\Component\DomCrawler\Link Returns a Link object for the first node in the list.
links ( ) : Symfony\Component\DomCrawler\Link[] Returns an array of Link objects for the nodes in the list.
nextAll ( ) : Crawler Returns the next siblings nodes of the current selection.
nodeName ( ) : string Returns the node name of the first node of the list.
parents ( ) : Crawler Returns the parents nodes of the current selection.
previousAll ( ) : Crawler Returns the previous sibling nodes of the current selection.
reduce ( Closure $closure ) : Crawler Reduces the list of nodes by calling an anonymous function.
registerNamespace ( string $prefix, string $namespace )
selectButton ( string $value ) : Crawler Selects a button by name or alt value for images.
selectImage ( string $value ) : Crawler Selects images by alt value.
selectLink ( string $value ) : Crawler Selects links by name or alt value for clickable images.
setDefaultNamespacePrefix ( string $prefix ) Overloads a default namespace prefix to be used with XPath and CSS expressions.
siblings ( ) : Crawler Returns the siblings nodes of the current selection.
slice ( integer $offset, integer $length = null ) : Crawler Slices the list of nodes by $offset and $length.
text ( ) : string Returns the node value of the first node of the list.
xpathLiteral ( string $s ) : string Converts string for XPath expressions.

Защищенные методы

Метод Описание
sibling ( DOMElement $node, string $siblingDir = 'nextSibling' ) : array

Приватные методы

Метод Описание
createDOMXPath ( DOMDocument $document, array $prefixes = [] ) : DOMXPath
createSubCrawler ( DOMElement | DOMElement[] | DOMNodeList | null $nodes ) : static Creates a crawler for some subnodes.
discoverNamespace ( DOMXPath $domxpath, string $prefix ) : string
filterRelativeXPath ( string $xpath ) : Crawler Filters the list of nodes with an XPath expression.
findNamespacePrefixes ( string $xpath ) : array
relativize ( string $xpath ) : string Make the XPath relative to the current context.

Описание методов

__construct() публичный Метод

public __construct ( mixed $node = null, string $currentUri = null, string $baseHref = null )
$node mixed A Node to use as the base for the crawling
$currentUri string The current URI
$baseHref string The base href value

add() публичный Метод

This method uses the appropriate specialized add*() method based on the type of the argument.
public add ( DOMNodeList | DOMNode | array | string | null $node )
$node DOMNodeList | DOMNode | array | string | null A node

addContent() публичный Метод

If the charset is not set via the content type, it is assumed to be ISO-8859-1, which is the default charset defined by the HTTP 1.1 specification.
public addContent ( string $content, null | string $type = null )
$content string A string to parse as HTML/XML
$type null | string The content type of the string

addDocument() публичный Метод

Adds a \DOMDocument to the list of nodes.
public addDocument ( DOMDocument $dom )
$dom DOMDocument A \DOMDocument instance

addHtmlContent() публичный Метод

The libxml errors are disabled when the content is parsed. If you want to get parsing errors, be sure to enable internal errors via libxml_use_internal_errors(true) and then, get the errors via libxml_get_errors(). Be sure to clear errors with libxml_clear_errors() afterward.
public addHtmlContent ( string $content, string $charset = 'UTF-8' )
$content string The HTML content
$charset string The charset

addNode() публичный Метод

Adds a \DOMNode instance to the list of nodes.
public addNode ( DOMNode $node )
$node DOMNode A \DOMNode instance

addNodeList() публичный Метод

Adds a \DOMNodeList to the list of nodes.
public addNodeList ( DOMNodeList $nodes )
$nodes DOMNodeList A \DOMNodeList instance

addNodes() публичный Метод

Adds an array of \DOMNode instances to the list of nodes.
public addNodes ( array $nodes )
$nodes array An array of \DOMNode instances

addXmlContent() публичный Метод

The libxml errors are disabled when the content is parsed. If you want to get parsing errors, be sure to enable internal errors via libxml_use_internal_errors(true) and then, get the errors via libxml_get_errors(). Be sure to clear errors with libxml_clear_errors() afterward.
public addXmlContent ( string $content, string $charset = 'UTF-8', integer $options = LIBXML_NONET )
$content string The XML content
$charset string The charset
$options integer Bitwise OR of the libxml option constants LIBXML_PARSEHUGE is dangerous, see http://symfony.com/blog/security-release-symfony-2-0-17-released

attr() публичный Метод

Returns the attribute value of the first node of the list.
public attr ( string $attribute ) : string | null
$attribute string The attribute name
Результат string | null The attribute value or null if the attribute does not exist

children() публичный Метод

Returns the children nodes of the current selection.
public children ( ) : Crawler
Результат Crawler A Crawler instance with the children nodes

clear() публичный Метод

Removes all the nodes.
public clear ( )

count() публичный Метод

public count ( ) : integer
Результат integer

each() публичный Метод

The anonymous function receives the position and the node wrapped in a Crawler instance as arguments. Example: $crawler->filter('h1')->each(function ($node, $i) { return $node->text(); });
public each ( Closure $closure ) : array
$closure Closure An anonymous function
Результат array An array of values returned by the anonymous function

eq() публичный Метод

Returns a node given its position in the node list.
public eq ( integer $position ) : Crawler
$position integer The position
Результат Crawler A new instance of the Crawler with the selected node, or an empty Crawler if it does not exist

evaluate() публичный Метод

Since an XPath expression might evaluate to either a simple type or a \DOMNodeList, this method will return either an array of simple types or a new Crawler instance.
public evaluate ( string $xpath ) : array | Crawler
$xpath string An XPath expression
Результат array | Crawler An array of evaluation results or a new Crawler instance

extract() публичный Метод

You can extract attributes or/and the node value (_text). Example: $crawler->filter('h1 a')->extract(array('_text', 'href'));
public extract ( array $attributes ) : array
$attributes array An array of attributes
Результат array An array of extracted values

filter() публичный Метод

This method only works if you have installed the CssSelector Symfony Component.
public filter ( string $selector ) : Crawler
$selector string A CSS selector
Результат Crawler A new instance of Crawler with the filtered list of nodes

filterXPath() публичный Метод

The XPath expression is evaluated in the context of the crawler, which is considered as a fake parent of the elements inside it. This means that a child selector "div" or "./div" will match only the div elements of the current crawler, not their children.
public filterXPath ( string $xpath ) : Crawler
$xpath string An XPath expression
Результат Crawler A new instance of Crawler with the filtered list of nodes

first() публичный Метод

Returns the first node of the current selection.
public first ( ) : Crawler
Результат Crawler A Crawler instance with the first selected node

form() публичный Метод

Returns a Form object for the first node in the list.
public form ( array $values = null, string $method = null ) : Form
$values array An array of values for the form fields
$method string The method for the form
Результат Form A Form instance

getBaseHref() публичный Метод

Returns base href.
public getBaseHref ( ) : string
Результат string

getIterator() публичный Метод

public getIterator ( ) : ArrayIterator
Результат ArrayIterator

getNode() публичный Метод

public getNode ( integer $position ) : DOMElement | null
$position integer
Результат DOMElement | null

getUri() публичный Метод

Returns the current URI.
public getUri ( ) : string
Результат string

html() публичный Метод

Returns the first node of the list as HTML.
public html ( ) : string
Результат string The node html

image() публичный Метод

Returns an Image object for the first node in the list.
public image ( ) : Symfony\Component\DomCrawler\Image
Результат Symfony\Component\DomCrawler\Image An Image instance

images() публичный Метод

Returns an array of Image objects for the nodes in the list.
public images ( ) : Symfony\Component\DomCrawler\Image[]
Результат Symfony\Component\DomCrawler\Image[] An array of Image instances

last() публичный Метод

Returns the last node of the current selection.
public last ( ) : Crawler
Результат Crawler A Crawler instance with the last selected node

nextAll() публичный Метод

Returns the next siblings nodes of the current selection.
public nextAll ( ) : Crawler
Результат Crawler A Crawler instance with the next sibling nodes

nodeName() публичный Метод

Returns the node name of the first node of the list.
public nodeName ( ) : string
Результат string The node name

parents() публичный Метод

Returns the parents nodes of the current selection.
public parents ( ) : Crawler
Результат Crawler A Crawler instance with the parents nodes of the current selection

previousAll() публичный Метод

Returns the previous sibling nodes of the current selection.
public previousAll ( ) : Crawler
Результат Crawler A Crawler instance with the previous sibling nodes

reduce() публичный Метод

To remove a node from the list, the anonymous function must return false.
public reduce ( Closure $closure ) : Crawler
$closure Closure An anonymous function
Результат Crawler A Crawler instance with the selected nodes

registerNamespace() публичный Метод

public registerNamespace ( string $prefix, string $namespace )
$prefix string
$namespace string

selectButton() публичный Метод

Selects a button by name or alt value for images.
public selectButton ( string $value ) : Crawler
$value string The button text
Результат Crawler A new instance of Crawler with the filtered list of nodes

selectImage() публичный Метод

Selects images by alt value.
public selectImage ( string $value ) : Crawler
$value string The image alt
Результат Crawler A new instance of Crawler with the filtered list of nodes

setDefaultNamespacePrefix() публичный Метод

Overloads a default namespace prefix to be used with XPath and CSS expressions.
public setDefaultNamespacePrefix ( string $prefix )
$prefix string

sibling() защищенный Метод

protected sibling ( DOMElement $node, string $siblingDir = 'nextSibling' ) : array
$node DOMElement
$siblingDir string
Результат array

siblings() публичный Метод

Returns the siblings nodes of the current selection.
public siblings ( ) : Crawler
Результат Crawler A Crawler instance with the sibling nodes

slice() публичный Метод

Slices the list of nodes by $offset and $length.
public slice ( integer $offset, integer $length = null ) : Crawler
$offset integer
$length integer
Результат Crawler A Crawler instance with the sliced nodes

text() публичный Метод

Returns the node value of the first node of the list.
public text ( ) : string
Результат string The node value

xpathLiteral() публичный статический Метод

Escaped characters are: quotes (") and apostrophe ('). Examples: 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')
public static xpathLiteral ( string $s ) : string
$s string String to be escaped
Результат string Converted string

Описание свойств

$uri защищенное свойство

The current URI
protected $uri