Comments (4)
set this option
option = uc.ChromeOptions() option.add_argument("--disable-gpu") driver = uc.Chrome(options=option)
I tried that and it did not work. Chrome processes are still open in the background.
from undetected-chromedriver.
set this option
option = uc.ChromeOptions() option.add_argument("--disable-gpu") driver = uc.Chrome(options=option)
from undetected-chromedriver.
set this option
option = uc.ChromeOptions() option.add_argument("--disable-gpu") driver = uc.Chrome(options=option)
I tried that and it did not work. Chrome processes are still open in the background.
from undetected-chromedriver.
Thank you for linking me #1767 (comment)
I "fixed" my problem with the help of their code.
Now after my Bot executes the driver.quit() - it also terminates the chrome.exe processes.
I fixed by adding this:
def cleanup_processes(self):
try:
tasks = subprocess.check_output(['tasklist'], encoding='utf-8')
if 'chrome.exe' in tasks:
subprocess.run(["taskkill", "/F", "/IM", "chrome.exe", "/T"], check=True)
logging.info("Chrome processes killed.")
else:
logging.info("No Chrome processes found.")
if 'chromedriver.exe' in tasks:
subprocess.run(["taskkill", "/F", "/IM", "chromedriver.exe", "/T"], check=True)
logging.info("Chromedriver processes killed.")
else:
logging.info("No Chromedriver processes found.")
except subprocess.CalledProcessError as e:
logging.error(f"Error checking or killing processes: {e}")
And then:
logging.basicConfig(filename='twitter_bot.log', level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')
twitter_bot = TwitterBot()
try:
while True:
twitter_bot.sendReply()
# Increment the iteration count
twitter_bot.iteration_count += 1
# Check if the restart condition is met
if twitter_bot.iteration_count >= twitter_bot.restart_interval:
print(f'Restarting session after {twitter_bot.restart_interval} iterations...')
twitter_bot.driver.quit() # Close the current session
time.sleep(twitter_bot.sleepTime * 2)
twitter_bot.cleanup_processes() # Cleanup Chrome and Chromedriver processes
twitter_bot = TwitterBot() # Start a new session
twitter_bot.iteration_count = 0
except Exception as e:
logging.error(f'Something went wrong: {e}. Restarting browser session...')
twitter_bot.driver.quit() # Close the current session
time.sleep(twitter_bot.sleepTime * 2)
twitter_bot.cleanup_processes() # Cleanup Chrome and Chromedriver processes
twitter_bot = TwitterBot() # Start a new session
from undetected-chromedriver.
Related Issues (20)
- memory leak 50 MB per page HOT 1
- Getting detected by https://ieeexplore.ieee.org/
- nodriver infinite wait on page load HOT 2
- nodriver detect browser closed
- backgroup chromedriver not quit HOT 1
- Nodriver: CDP get_response_body command not working HOT 1
- What is the different between undetected-chromedriver and nodriver HOT 2
- WebAssembly module because 'unsafe-eval' HOT 1
- Nodriver: cdp.page.add_script_to_evaluate_on_new_document NOT WORK HOT 2
- Add cookies to nodriver from httpx or requests HOT 2
- is there a way to load json cookies in nodriver? like in uc HOT 1
- AWS EC2 Linux Server Detected Despite Manipulated Headers Using Undetected Chromedriver HOT 9
- cloud fare CAPTCHA
- Cannot pass cloudflare "Verify you are human" click
- Detected on Twitch
- NoDriver: can't find element – Add to cart button HOT 1
- How do I free up all the resources? HOT 2
- no driver, looking for proxies solution HOT 9
- chrome driver forces https
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from undetected-chromedriver.