elebumm / RedditVideoMakerBot

Create Reddit Videos with just✨ one command ✨
GNU General Public License v3.0
6.69k stars 1.87k forks source link

[Bug]: waiting for locator("[name=\"username\"]") #1925

Closed akhlaq12 closed 8 months ago

akhlaq12 commented 10 months ago

Describe the bug

It was working fine, but suddenly an error appeared:

│ Error: Timeout 30000ms exceeded. │ │ =========================== logs =========================== │ │ waiting for locator("[name=\"username\"]")

Expected behavior

Snapping reddit post screenshots

Screenshots

Capture

System Information

Operating System : Win 10 Python version : Python 3.10.0

Checklist

Additional Context

No response

joshholly commented 10 months ago

Same issue, I get that or:

Error: strict mode violation: locator("[name=\"username\"]") resolved to 3 elements

HLdota commented 10 months ago

The login page is blocked due to a problem with our identifier. That's why we can't log in. Just change [settings]-storymode = true in the config.toml file to toggle the mode or use a different type.

littlerspade commented 10 months ago

Same Issue.

SellersEvan commented 10 months ago

I have the same issue, but it seems to "randomly" work sometimes.

CaptainDigitals commented 10 months ago

The randomly works sometimes is what drives me nuts.

The error message indicates a timeout while waiting for the username field to become available to fill in. This could be due to a few reasons:

The page hasn't loaded completely, or it's taking too long to load.
The locator used to find the username field ([name="username"]) might be incorrect or not specific enough.
The website might have changed its structure, so the locator is no longer valid.

To address this, suggests the following steps:

Verify the webpage's loading time and ensure the page is fully loaded before locating the username field.
Check the accuracy of the locator. Inspect the webpage to confirm if [name="username"] is the correct way to identify the username field.
Add error handling to manage timeouts more gracefully.

Need to increase the wait time to search for the username field or increase the wait time for the site to load in the headless browser.

hamzakharbouch commented 10 months ago

I have the same issue

robinaerts commented 10 months ago

Quick workaround is to set

headless=False

in the _screenshotdownloader.py file.

Looks like reddit is trying to block webscrapers.

akhlaq12 commented 10 months ago

Quick workaround is to set

headless=False

in the _screenshotdownloader.py file.

Looks like reddit is trying to block webscrapers.

Its worked perfectly, Thank you

SellersEvan commented 10 months ago

Adding a user agent seems to also work. But sometime it still fails, but for other reasons. Let me know if this works for you guys and I can make a pull request with the update.

        useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36"
        browser = p.chromium.launch(
            headless=True,
            args=[
                f'--user-agent={useragent}',
            ]
        )  # headless=False will show the browser for debugging purposes
akhlaq12 commented 10 months ago

It worked well for me :) Thank You

akhlaq12 commented 10 months ago

Adding a user agent seems to also work. But sometime it still fails, but for other reasons. Let me know if this works for you guys and I can make a pull request with the update.

        useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36"
        browser = p.chromium.launch(
            headless=True,
            args=[
                f'--user-agent={useragent}',
            ]
        )  # headless=False will show the browser for debugging purposes

It worked well for me :) Thank You

SellersEvan commented 10 months ago

If you run a bunch of iterations it seems to randomly pass and fail. My though was we could bypass needing to access the website (and playwright) all together. We can do this by grabbing the data needed and generating HTML to render it with the comment information. Any thoughts on this?

SellersEvan commented 10 months ago

If you run a bunch of iterations it seems to randomly pass and fail. My though was we could bypass needing to access the website (and playwright) all together. We can do this by grabbing the data needed and generating HTML to render it with the comment information. Any thoughts on this?

This user has created a similar but different way of accessing Reddit without signing in. They used selenium instead of playwright: https://github.com/Shifty-The-Dev/RedditVideoGenerator

I could be wrong, but I believe playwright uses selenium on the backend.

joshholly commented 10 months ago

So I turned off "headless" and what I've noticed is that sometimes it takes me to the reddit homepage without the login fields, instead of the login page (despite the URL in the script being reddit.com/login. So it looks like /login is redirecting back to the home page sometimes.

Anyway to fix this?

SellersEvan commented 10 months ago

If you run a bunch of iterations it seems to randomly pass and fail. My though was we could bypass needing to access the website (and playwright) all together. We can do this by grabbing the data needed and generating HTML to render it with the comment information. Any thoughts on this?

This user has created a similar but different way of accessing Reddit without signing in. They used selenium instead of playwright: https://github.com/Shifty-The-Dev/RedditVideoGenerator

I could be wrong, but I believe playwright uses selenium on the backend.

Then it would be much easier to switch playwright to selenium. (Could be wrong) There has to be some kind of fix to this right?

Also SellersEvan how can I use the user agent fix? Whenever I put that code in it tells me user agent is not defined...

You should just have to add a string with the desired UA and add it as an argument to the chromium launch.

        useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36"
        browser = p.chromium.launch(
            headless=True,
            args=[
                f'--user-agent={useragent}',
            ]
        )
joshholly commented 9 months ago

I fixed the issue by making it use my own local Chrome instead of playwrite's chromium. In screenshot.py replace this part:

   browser = p.chromium.launch(
            headless=True
        )

With

 chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
 browser = p.chromium.launch(
    headless=True,
    executable_path=chrome_path
        )

(on MacOS)

However, if you're on windows do:

chrome_path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
browser = p.chromium.launch(
            headless=True,
            executable_path=chrome_path
        )

Appologies for the weird spacing. Space it properly. But basically, you get the gist, have it launch from your local chrome. This way it will use your own native browser to grab screenshots makaing it look more legit.

hamzakharbouch commented 9 months ago

please guys how can i filters the posts ( Date with Top , New , Hot ? )

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 7 days with no activity. Remove stale label or comment, or this will be closed in 10 days.

SellersEvan commented 9 months ago

I have started a new project for making TikTok videos, because this codebase got too bloated. The new project doesn't support all the same features but hopefully it will eventually. Right now, it just does memes from Reddit. Feel free to check it out and maybe contribute. https://github.com/sellersindustry/tiktok-meme-bot

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 7 days with no activity. Remove stale label or comment, or this will be closed in 10 days.

github-actions[bot] commented 8 months ago

Issue closed due to being stale. Please reopen if issue persists in latest version.

Yaroslav4232 commented 7 months ago

I still get this error, I don't understand how to fix it. Can someone help?

Elwii04 commented 7 months ago

Same. All fixes proposed didn't do it for me

dsaderholm commented 7 months ago

I also am having issues. I have tried all the fixes.