sniffingpickles / Auto-Amazon-Giveaways

Automated Amazon Giveaways using Python3 & Pyppeteer :gift: :snake:
6 stars 8 forks source link

** Could not find Next Page for GiveAways, Exiting... ** #19

Closed leptoid closed 5 years ago

leptoid commented 5 years ago

This is the same as the person below me, I thought I'd put the error received though. I think the other guy says he doesn't get an error... Logs in, goes to auction page, loads, fails as follows.

(base) C:\Bin_\Git\Auto-Amazon-Giveaways>python give_it_away_now.py
Log into Amazon...
Enter your Amazon email address: torpedo_tom_turellie@hotmail.com
Enter your Amazon password: I_Hope_You_Realize_This_Is_Not_My_Password_Or_Email
*** no giveaways returned ***
** Could not find Next Page for GiveAways, Exiting... **
adam-stamand commented 5 years ago

It looks to me like the bot is looking for a list item with a class name of 'li.a-last'

https://github.com/sniffingpickles/Auto-Amazon-Giveaways/blob/933e7d61278de4ee9b01be47f28338d25ea1ee14/lib/giveaway.py#L328

But, it seems that the Amazon giveaway page doesn't always have a list item with that name. You can see this in Chromium by right clicking on the page and clicking "Inspect". Scroll down to where the Next button is and sometimes the list item will not have a class name ('a-last') and instead will just have a hyperlink tag () with an id.

I know next to nothing about web page stuff, but I put together a solution that worked for me. You can replace the iterate_page method with the following:


    async def iterate_page(self, ga_page):
        try:
            # Look for the "Next" button using an ID
            next_button = await ga_page.querySelector(
                "[id*='pagination_buttonNext']")

            # If "Next" button not found using ID, try to find it using the list item
            if (not next_button):
                next_button = await ga_page.querySelector('li.a-last')

            # The "Next" button cannot be found, error
            if (not next_button):
                msg = Fore.LIGHTRED_EX + Style.BRIGHT + \
                    "**** Could not find Next Page for GiveAways, Exiting... ****"
                print(msg)
                quit(1)

            # Now that the "Next" button has been found, click it to go to the next page
            await next_button.click()
            msg = Fore.LIGHTGREEN_EX + Style.BRIGHT + \
                "**** Moving to next giveaway page ****"
            print(msg)

            # Wait for the page to load
            # TODO It's necessary to wait for the page to load, but there must be
            # a better way than waiting for a fixed time (2 seconds)
            await asyncio.sleep(2)

            return ga_page

        except errors.PageError:
            ""

The method above first looks for the hyper link tag with an id of 'pagination_buttonNext'. If it can't find that, then it looks for the list item with a class name of 'a-last'.

I also changed the method to use clicking instead of loading the href, mostly because I didn't know how to get the href from the hyper link tag. So now it locates the Next button using either the list item class name or the hyperlink id, and then it just clicks the next button for you. I had to put a delay to give time for the page to load, but surely there's a better way.

juancarlosgzrz commented 5 years ago

@adam-stamand can you upload a fork with your changes?

juancarlosgzrz commented 5 years ago

@adam-stamand now is working but it stops and says:

image

sniffingpickles commented 5 years ago

There's a lot of syntax to update on the page, which will cause error. If you can't debug the error, I recommend investing time to learn the cause.

juancarlosgzrz commented 5 years ago

I wasn't talking to you man, I was talking to Adam, if you don't want to fix the issue other will do. Thanks

sniffingpickles commented 5 years ago

I wasn't talking to you man, I was talking to Adam, if you don't want to fix the issue other will do. Thanks

Then go to their repo, this one is mine and I get notified on every comment you make lol. Stop thread hopping, and contact them directly.