|
@@ -17,6 +17,8 @@ use Symfony\Component\CssSelector\Parser as CssParser;
|
|
|
* Crawler eases navigation of a list of \DOMNode objects.
|
|
|
*
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
class Crawler extends \SplObjectStorage
|
|
|
{
|
|
@@ -32,6 +34,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param string $uri The base URI to use for absolute links or form actions
|
|
|
* @param string $base An optional base href for generating the uris for Form and Link.
|
|
|
* This will be autodetected if $node has a <base> tag.
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function __construct($node = null, $uri = null, $base = null)
|
|
|
{
|
|
@@ -48,6 +52,8 @@ class Crawler extends \SplObjectStorage
|
|
|
|
|
|
/**
|
|
|
* Removes all the nodes.
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function clear()
|
|
|
{
|
|
@@ -61,6 +67,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* on the type of the argument.
|
|
|
*
|
|
|
* @param null|\DOMNodeList|array|\DOMNode $node A node
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function add($node)
|
|
|
{
|
|
@@ -75,6 +83,12 @@ class Crawler extends \SplObjectStorage
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Adds HTML/XML content.
|
|
|
+ *
|
|
|
+ * @param string $content A string to parse as HTML/XML
|
|
|
+ * @param string $type The content type of the string
|
|
|
+ */
|
|
|
public function addContent($content, $type = null)
|
|
|
{
|
|
|
if (empty($type)) {
|
|
@@ -103,6 +117,8 @@ class Crawler extends \SplObjectStorage
|
|
|
*
|
|
|
* @param string $content The HTML content
|
|
|
* @param string $charset The charset
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function addHtmlContent($content, $charset = 'UTF-8')
|
|
|
{
|
|
@@ -124,6 +140,8 @@ class Crawler extends \SplObjectStorage
|
|
|
*
|
|
|
* @param string $content The XML content
|
|
|
* @param string $charset The charset
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function addXmlContent($content, $charset = 'UTF-8')
|
|
|
{
|
|
@@ -139,6 +157,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Adds a \DOMDocument to the list of nodes.
|
|
|
*
|
|
|
* @param \DOMDocument $dom A \DOMDocument instance
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function addDocument(\DOMDocument $dom)
|
|
|
{
|
|
@@ -151,6 +171,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Adds a \DOMNodeList to the list of nodes.
|
|
|
*
|
|
|
* @param \DOMNodeList $nodes A \DOMNodeList instance
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function addNodeList(\DOMNodeList $nodes)
|
|
|
{
|
|
@@ -163,6 +185,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Adds an array of \DOMNode instances to the list of nodes.
|
|
|
*
|
|
|
* @param array $nodes An array of \DOMNode instances
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function addNodes(array $nodes)
|
|
|
{
|
|
@@ -175,6 +199,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Adds a \DOMNode instance to the list of nodes.
|
|
|
*
|
|
|
* @param \DOMNode $node A \DOMNode instance
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function addNode(\DOMNode $node)
|
|
|
{
|
|
@@ -191,6 +217,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param integer $position The position
|
|
|
*
|
|
|
* @return A new instance of the Crawler with the selected node, or an empty Crawler if it does not exist.
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function eq($position)
|
|
|
{
|
|
@@ -218,6 +246,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param \Closure $closure An anonymous function
|
|
|
*
|
|
|
* @return array An array of values returned by the anonymous function
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function each(\Closure $closure)
|
|
|
{
|
|
@@ -237,6 +267,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param \Closure $closure An anonymous function
|
|
|
*
|
|
|
* @return Crawler A Crawler instance with the selected nodes.
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function reduce(\Closure $closure)
|
|
|
{
|
|
@@ -254,6 +286,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Returns the first node of the current selection
|
|
|
*
|
|
|
* @return Crawler A Crawler instance with the first selected node
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function first()
|
|
|
{
|
|
@@ -264,6 +298,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Returns the last node of the current selection
|
|
|
*
|
|
|
* @return Crawler A Crawler instance with the last selected node
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function last()
|
|
|
{
|
|
@@ -276,6 +312,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Crawler A Crawler instance with the sibling nodes
|
|
|
*
|
|
|
* @throws \InvalidArgumentException When current node is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function siblings()
|
|
|
{
|
|
@@ -292,6 +330,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Crawler A Crawler instance with the next sibling nodes
|
|
|
*
|
|
|
* @throws \InvalidArgumentException When current node is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function nextAll()
|
|
|
{
|
|
@@ -306,6 +346,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Returns the previous sibling nodes of the current selection
|
|
|
*
|
|
|
* @return Crawler A Crawler instance with the previous sibling nodes
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function previousAll()
|
|
|
{
|
|
@@ -322,6 +364,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Crawler A Crawler instance with the parents nodes of the current selection
|
|
|
*
|
|
|
* @throws \InvalidArgumentException When current node is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function parents()
|
|
|
{
|
|
@@ -347,6 +391,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Crawler A Crawler instance with the children nodes
|
|
|
*
|
|
|
* @throws \InvalidArgumentException When current node is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function children()
|
|
|
{
|
|
@@ -365,6 +411,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return string The attribute value
|
|
|
*
|
|
|
* @throws \InvalidArgumentException When current node is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function attr($attribute)
|
|
|
{
|
|
@@ -381,6 +429,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return string The node value
|
|
|
*
|
|
|
* @throws \InvalidArgumentException When current node is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function text()
|
|
|
{
|
|
@@ -403,6 +453,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param array $attributes An array of attributes
|
|
|
*
|
|
|
* @return array An array of extracted values
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function extract($attributes)
|
|
|
{
|
|
@@ -433,6 +485,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param string $xpath An XPath expression
|
|
|
*
|
|
|
* @return Crawler A new instance of Crawler with the filtered list of nodes
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function filterXPath($xpath)
|
|
|
{
|
|
@@ -457,6 +511,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Crawler A new instance of Crawler with the filtered list of nodes
|
|
|
*
|
|
|
* @throws \RuntimeException if the CssSelector Component is not available
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function filter($selector)
|
|
|
{
|
|
@@ -475,6 +531,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param string $value The link text
|
|
|
*
|
|
|
* @return Crawler A new instance of Crawler with the filtered list of nodes
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function selectLink($value)
|
|
|
{
|
|
@@ -490,6 +548,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @param string $value The button text
|
|
|
*
|
|
|
* @return Crawler A new instance of Crawler with the filtered list of nodes
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function selectButton($value)
|
|
|
{
|
|
@@ -508,6 +568,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Link A Link instance
|
|
|
*
|
|
|
* @throws \InvalidArgumentException If the current node list is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function link($method = 'get')
|
|
|
{
|
|
@@ -524,6 +586,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* Returns an array of Link objects for the nodes in the list.
|
|
|
*
|
|
|
* @return array An array of Link instances
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function links()
|
|
|
{
|
|
@@ -544,6 +608,8 @@ class Crawler extends \SplObjectStorage
|
|
|
* @return Form A Form instance
|
|
|
*
|
|
|
* @throws \InvalidArgumentException If the current node list is empty
|
|
|
+ *
|
|
|
+ * @api
|
|
|
*/
|
|
|
public function form(array $values = null, $method = null)
|
|
|
{
|