-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookies.py
38 lines (29 loc) · 1023 Bytes
/
cookies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
# Initialize WebDriver
driver = webdriver.Chrome()
# Target website
url = "https://x.com/HackHubAfrica"
try:
# Navigate to the target website
driver.get(url)
# Wait for the page to load completely
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "body"))
)
# Get cookies
cookies = driver.get_cookies()
# Save cookies to a JSON file
with open('cookies.json', 'w') as file:
json.dump(cookies, file, indent=4)
print("Cookies have been saved to cookies.json")
except TimeoutException:
print("Timed out waiting for page to load")
finally:
# Close the driver
driver.quit()