Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only getting first page of items #31

Open
chris-n-self opened this issue Jan 20, 2018 · 3 comments · May be fixed by #34
Open

Only getting first page of items #31

chris-n-self opened this issue Jan 20, 2018 · 3 comments · May be fixed by #34

Comments

@chris-n-self
Copy link

I'm on the UK amazon site, and if I view wishlists on the website it loads more items as you scroll down the page. The script is only returning the items that are displayed when the page first opens, not the hidden items that you have to scroll down to see.

@chris-n-self
Copy link
Author

I dug through the html of the wishlist page a little bit and found this at the end of the items sections, <script type="a-state" data-a-state="{&quot;key&quot;:&quot;scrollState&quot;}">{"showMoreUrl": it's followed by a URL that if I copy and paste into my browser takes me to the 'second page' of items. Following the chain of pages, when you're at the end of the wishlist that field is missing from the html. I can imagine maybe it's possible to grab that URL and go to the next page to get the next items, repeating until the field is missing. But I don't understand how the phpQuery is working well enough to try it myself, without it taking a while.

@chris-n-self
Copy link
Author

chris-n-self commented Feb 2, 2018

I got this working, the "showMoreUrl" uses a field in the url called last evaluated key &lek= to point to the next set of items. I can grab that from the current page with,

$next_page = pq('script[data-a-state=\'{"key":"scrollState"}\']')->html()
preg_match("/\"lastEvaluatedKey\":\"(.*)\"/", $next_page, $next_page_url)
$lek = $next_page_url[1]

The $lek really just work like pages, the items shown on each do not overlap with each other. So (in my local copy of the code) I've just replaced the loop over page_num with,

$lek = ''
do {
      $contents = phpQuery::newDocumentFile("$baseurl/registry/$amazon_id?...&lek=$lek");
      ...
      // get new value of $lek here
} while(!$lek == '');

where I've just appended &lek=$lek onto the end of the url in the phpQuery::newDocumentFile call.

@zervel zervel linked a pull request Aug 15, 2018 that will close this issue
@blobaugh
Copy link

I am experiencing the same issue. I have verified that PR #34 does fix the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants