PHP 클래스 Symfony\Component\DomCrawler\Crawler

저자: Fabien Potencier ([email protected])
상속: extends SplObjectStorage
파일 보기 프로젝트 열기: symfony/dom-crawler 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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() 공개 메소드

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