Skip to content

How to restart the browser with pytest? #2382

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

Closed
mIgLLL opened this issue Dec 22, 2023 · 1 comment
Closed

How to restart the browser with pytest? #2382

mIgLLL opened this issue Dec 22, 2023 · 1 comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@mIgLLL
Copy link

mIgLLL commented Dec 22, 2023

  1. I have millons of urls and need to crawl the data from the website.
  2. The anti-crawling technologies restrict that one broswer can only crawl ten pages, then you must close the browser and restart it again.
  3. I find that pytest is designed for web testing, not crawling website, it's hard to restart the browser.
  4. When starting a broswer, I need to load four chrome extensions, which makes it more complicated.
  5. multi-thread is necessary

Any tips will help. Thank you!

@mdmintz mdmintz added question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Dec 23, 2023
@mdmintz
Copy link
Member

mdmintz commented Dec 23, 2023

You can always open a fresh, new browser for your tests in the middle of a test:

self.get_new_driver(undetectable=True)

And you can close your existing browser window with:
self.driver.quit().

For loading multiple Chrome extensions in the pytest format that uses BaseCase, use:
pytest --extension-dir=DIR1,DIR2,DIR3,DIR4
(Comma-separated format)

For multi-threading with pytest, see #2006 (comment)

Note that even if you use UC Mode to bypass detection, if you send too many requests (too much traffic), they may still block your IP Address.

@mdmintz mdmintz closed this as completed Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants