test isn't done

This commit is contained in:
Valentin CZERYBA 2024-02-12 22:49:17 +01:00
parent 6e7bf72ef2
commit 097bf3b0fb

View File

@ -1,4 +1,4 @@
import time
import time, requests, os
from selenium import webdriver #Webdriver de Selenium qui permet de contrôler un navigateur
from webdriver_manager.chrome import ChromeDriverManager #Assure la gestion du webdriver de Chrome
from selenium.webdriver.chrome.options import Options
@ -8,18 +8,44 @@ from selenium.webdriver.common.by import By
chrome_options = Options()
#chrome_options.add_argument("--headless=new") # for Chrome >= 109
parameter = {}
browser = webdriver.Chrome() #Initialisation du driver
browser.get("https://fetlife.com/login")
user_agent = browser.execute_script("return navigator.userAgent;")
time.sleep(1)
print("user-agent : {0}".format(user_agent))
print("authencity_token : {0}".format(browser.find_element(By.NAME, "authenticity_token").get_attribute("value")))
parameter["authencity_token"]=browser.find_element(By.NAME, "authenticity_token").get_attribute("value")
authencity_token=browser.find_element(By.NAME, "authenticity_token").get_attribute("value")
cookie = ["_cfuvid", "__cf_bm", "_fl_sessionid", "cf_clearance", "fetlife_pwa", "language"]
cookies = {}
for i in cookie:
if browser.get_cookie(i) is not None:
print("{0}: {1}".format(i, browser.get_cookie(i)["value"]))
parameter[i]=browser.get_cookie(i)["value"]
cookies[i]=browser.get_cookie(i)["value"]
browser.quit()
print(parameter)
headers = {"Connection":"keep-alive",
"Host":"fetlife.com",
"Cache-Control":"max-age=0",
"Origin":"https://fetlife.com",
"Referer":"https://fetlife.com/login", "User-Agent":user_agent, "TE": "trailers", "Upgrade-Insecure-Requests":"1",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Content-Type": "application/x-www-form-urlencoded",
"DNT":"1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode":"navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User":"?!",
"Set-GPC":"1",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language":"fr-FR,fr;q=0.9"
}
payload = {"authenticy_token":authencity_token, "button":"", "fake_username":"", "fake_safari_password":"", "user":{"otp_attempt":"step_1","locale":"fr","login":os.environ["USER"],"password":os.environ["PASSWORD"]}}
data_raw = "fake_username=&fake_safari_password=&authenticity_token={0}&user%5Botp_attempt%5D=step_1&user%5Blocale%5D=fr&user%5Blogin%5D={1}&user%5Bpassword%5D={2}&button=".format(authencity_token, os.environ["USER"], os.environ["PASSWORD"])
print(headers)
print(cookies)
print(data_raw)
r = requests.post("https://fetlife.com/login", headers=headers, data=payload, cookies=cookies)
print(r.status_code)
#print(r.content)