{"id":3571,"date":"2016-04-06T09:31:23","date_gmt":"2016-04-06T15:31:23","guid":{"rendered":"http:\/\/bililite.com\/blog\/?p=3571"},"modified":"2016-04-06T09:32:53","modified_gmt":"2016-04-06T15:32:53","slug":"getting-multiple-pages-in-the-amazon-wish-list","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2016\/04\/06\/getting-multiple-pages-in-the-amazon-wish-list\/","title":{"rendered":"Getting multiple pages in the Amazon Wish List"},"content":{"rendered":"<p>I figured out how to get all the pages from <a href=\"http:\/\/bililite.com\/blog\/2016\/04\/05\/again-to-an-amazon-wishlist-widget\/\" title=\"Hacking My Way Again to an Amazon Wishlist Widget\">screen-scraping the Amazon wish list<\/a>. Basically, look for the \"Next\" button (it's in a <code class=\"language-html\" >&lt;li class=a-last&gt;<\/code> element). If that element is present, look for the next page. <\/p>\n<pre><code class=\"language-php\" >function getwishlistitems ($listID, $page=1){\r\n\t\/\/ ignore parsing warnings\r\n\t$wishlistdom = new DOMDocument();\r\n\t@$wishlistdom->loadHTMLFile(\"http:\/\/www.amazon.com\/gp\/registry\/wishlist\/$listID?disableNav=1&page=$page\");\r\n\t$wishlistxpath = new DOMXPath ($wishlistdom);\r\n\t$items = iterator_to_array($wishlistxpath->query(\"\/\/div[starts-with(@id,'item_')]\"));\r\n\tif ($wishlistxpath->evaluate(\"count(\/\/li[@class='a-last'])\")) { \/\/ this is the \"Next->\" button\r\n\t\t$items = array_merge($items, $this->getwishlistitems($listID, $filter, $page+1));\r\n\t}\r\n\treturn $items;\r\n}<\/code><\/pre>\n<p>Note that this creates a complication: the array of items now includes nodes from different documents, so you can't use one saved <code class=\"language-html\" >DOMXPath<\/code>. Instead, where the original code has <code class=\"language-php\" >$wishlistxpath->evaluate($xpath, $node)<\/code>, use<\/p>\n<pre><code class=\"language-php\" >(new DOMXPath($node->ownerDocument))->evaluate($xpath, $node);<\/code><\/pre>\n<p>Hope this helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I figured out how to get all the pages from screen-scraping the Amazon wish list. Basically, look for the \"Next\" button (it's in a &lt;li class=a-last&gt; element). If that element is present, look for the next page. function getwishlistitems ($listID, $page=1){ \/\/ ignore parsing warnings $wishlistdom = new DOMDocument(); @$wishlistdom->loadHTMLFile(\"http:\/\/www.amazon.com\/gp\/registry\/wishlist\/$listID?disableNav=1&#038;page=$page\"); $wishlistxpath = new DOMXPath ($wishlistdom); [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3571"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=3571"}],"version-history":[{"count":2,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3571\/revisions"}],"predecessor-version":[{"id":3574,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3571\/revisions\/3574"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=3571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=3571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=3571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}