
+++ utils/cache_clear.py
... | ... | @@ -0,0 +1,27 @@ |
1 | +import undetected_chromedriver as uc | |
2 | +from selenium.webdriver.common.action_chains import ActionChains | |
3 | +from selenium.webdriver.common.keys import Keys | |
4 | +from webdriver_manager.chrome import ChromeDriverManager | |
5 | +from time import sleep | |
6 | + | |
7 | + | |
8 | +options = uc.ChromeOptions() | |
9 | +driver = uc.Chrome(driver_executable_path=ChromeDriverManager().install(), options=options) | |
10 | + | |
11 | +def delete_cache(driver): | |
12 | + driver.execute_script("window.open('')") # Create a separate tab than the main one | |
13 | + driver.switch_to.window(driver.window_handles[-1]) # Switch window to the second tab | |
14 | + driver.get('chrome://settings/clearBrowserData') # Open your chrome settings. | |
15 | + sleep(3) | |
16 | + actions = ActionChains(driver) | |
17 | + actions.key_down(Keys.SHIFT).send_keys(Keys.TAB * 6).key_up(Keys.SHIFT) #select "all time" browsing data | |
18 | + actions.perform() | |
19 | + sleep(3) | |
20 | + actions.send_keys(Keys.DOWN * 5 + Keys.TAB * 7 + Keys.ENTER) #click on "clear data" button | |
21 | + actions.perform() | |
22 | + sleep(3) | |
23 | + driver.close() | |
24 | + driver.switch_to.window(driver.window_handles[0]) | |
25 | + print("Succesfully cleared the browsing data") | |
26 | + | |
27 | +# delete_cache(driver)(파일 끝에 줄바꿈 문자 없음) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?