# Scrape Lists

Scraping lists follows a similar approach as other scraping with PHPScraper:

$web = new \Spekulatius\PHPScraper\PHPScraper;

/**
 * Navigate to the test page. This page contains:
 *
 * <h2>Example 1: Unordered List</h2>
 * <ul>
 *     <li>Unordered list item 1</li>
 *     <li>Unordered list item 2</li>
 *     <li>Unordered list item with <b>HTML</b></li>
 * </ul>
 *
 * <h2>Example 2: Ordered List</h2>
 * <ol>
 *     <li>Ordered list item 1</li>
 *     <li>Ordered list item 2</li>
 *     <li>Ordered list item with <i>HTML</i></li>
 * </ol>
 */
$web->go('https://test-pages.phpscraper.de/content/lists.html');

/**
 * Only unordered lists (<ul>)
 *
 * [
 *     "type" => "ul",
 *     "children" => ... // List of childNodes
 *     "children_plain" =>
 *     [
 *         "Unordered list item 1"
 *         "Unordered list item 2"
 *         "Unordered list item with HTML"
 *     ]
 * ]
 */
var_dump($web->unorderedLists);


/**
 * Only ordered lists (<ol>)
 *
 * [
 *     "type" => "ul",
 *     "children" => ... // List of childNodes
 *     "children_plain" =>
 *     [
 *         "Ordered list item 1"
 *         "Ordered list item 2"
 *         "Ordered list item with HTML"
 *     ]
 * ]
 */
var_dump($web->orderedLists);


// Both lists combined (as above)
var_dump($web->lists);

Nested Lists

At the moment, this doesn't handle nested lists well. Nested lists are included in the result as children to allow further processing.