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

Simply does not work #4

Open
ThomasAitken opened this issue Mar 29, 2021 · 4 comments
Open

Simply does not work #4

ThomasAitken opened this issue Mar 29, 2021 · 4 comments

Comments

@ThomasAitken
Copy link

I ran both the synced and async versions of your basic user-agent example with Chromium (using the latest version of playwright-python, and the standard pip version of your package) and the screenshot in both cases shows a user agent containing "HeadlessChrome". Obviously, this is not as advertised - the user agent has not been edited.

@AtuboDad
Copy link
Owner

I ran both the synced and async versions of your basic user-agent example with Chromium (using the latest version of playwright-python, and the standard pip version of your package) and the screenshot in both cases shows a user agent containing "HeadlessChrome". Obviously, this is not as advertised - the user agent has not been edited.

which version of packages?

Version:
playwright-python >= 1.9.0
playwright-stealth =1.0.5

Last:
Use the Chrome on yourself OS.

Like this:
`# -- coding: utf-8 --
from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync

playwright_sync = sync_playwright().start()

executablePath = 'C:\Google\Chrome\Application\chrome.exe'
args = ['--no-sandbox', '--disable-infobars', '--lang=zh-CN', '--window-size=1920,1080', '--start-maximized']
ignoreDefaultArgs = ['--enable-automation']
browser = playwright_sync.chromium.launch(executable_path=executablePath, args=args, ignore_default_args=ignoreDefaultArgs, headless=True)
page = browser.new_page()
stealth_sync(page)

page.set_viewport_size({"width": 1920, "height": 969})
page.goto("https://bot.sannysoft.com/", timeout=180000)
page.wait_for_timeout(3000)
page.screenshot(path="example1.png")
browser.close()
playwright_sync.stop()
`

@ThomasAitken
Copy link
Author

Turns out that website (https://bot.sannysoft.com/) does show all tests passing using Chromium with my OS browser and with the playwright executable. But http://whatsmyuseragent.org/ fails with both.

@kuranai
Copy link

kuranai commented Nov 3, 2021

Hi, I also thought that it does not work, so I found this issue.
But if I create a context and assign the user agent there, then it works for me.
Here is the example of what works for me, in case anyone else ends up here:

from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync


with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
        user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
    )
    page = context.new_page()
    stealth_sync(page)
    page.goto("https://bot.sannysoft.com/", wait_until="networkidle", timeout=10000)
    page.screenshot(path="screenshot.png")
    browser.close()

screenshot1
bot sannysoft com

@JoshYuJump
Copy link

JoshYuJump commented Jul 12, 2024

Same Issue here.

stealth.min.js works for me

async with async_playwright() as p:
    # launch the browser
    browser = await p.chromium.launch()
    context = await browser.new_context(
        user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
    )
    # stealth.min.js is a js script to prevent the website from detecting the crawler.
    await context.add_init_script(path="stealth.min.js")

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

No branches or pull requests

4 participants