Files
useful/scraper_utilities/cookies.py
2024-07-13 00:53:45 +03:00

49 lines
1.0 KiB
Python

"""
Used for capturing cookies after a request to specific website
"""
from time import sleep
import json
from selenium import webdriver
def check_captcha(driver, check_string):
print('Checking for captcha')
while check_string not in driver.page_source:
print('Found captcha. Waiting.')
sleep(5)
print('Captcha not found, proceeding')
def main():
SHOP_LINK = 'https://www.mwave.com.au/'
driver = webdriver.Firefox()
driver.get(SHOP_LINK)
# check_captcha(driver, 'Your current connection has triggered our security challenge, please complete the chall')
cookies = driver.get_cookies()
user_agent = driver.execute_script("return navigator.userAgent;")
print(user_agent)
# driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
# driver.get(l)
driver.close()
return cookies
def decode_cookies(cookies):
cookies_dict = {}
for i in cookies:
cookies_dict[i['name']] = i['value']
otp = json.dumps(cookies_dict)
with open('cookies.json', 'w') as f:
f.write(otp)
c = main()
decode_cookies(c)