1

I attempted to scrape a website that has a bot-blocker from cloudflare using this code:

with SB(uc=True, headless2=True) as sb:
    for url in urls:
        sb.uc_open_with_reconnect(url, 5)
        sb.uc_gui_handle_captcha()

There was an error:

Exception: PyAutoGUI can't be used in headless mode!

How can I pass the CAPTCHA in headless mode without PyAutoGUI? Or is there an alternative way to solve this problem?

I have tried many approaches, like using cookies, virtual display etc., and nothing worked.

2
  • Could you please share full error trace with. Now its unclear which line raises an error Commented Oct 6, 2024 at 2:26
  • Exception Traceback (most recent call last) Cell In[11], line 20 18 for url in urls: 19 sb.uc_open_with_reconnect(url, 5) ---> 20 sb.uc_gui_click_captcha() 22 has_next_page = True 24 while has_next_page: exception: PyAutoGUI can't be used in headless mode! Commented Oct 10, 2024 at 4:54

1 Answer 1

0

Use the SeleniumBase Xvfb virtual display to simulate headless mode in a headless environment on Linux:

For your script, the solution would look something like this:

from seleniumbase import SB

with SB(uc=True, xvfb=True) as sb:
    urls = [URL1, URL2]
    for url in urls:
        sb.uc_open_with_reconnect(url, 5)
        sb.uc_gui_click_captcha()
        # Do more stuff here

(Note that Xvfb is for Linux environments. Don't use headless mode with UC Mode.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.