Created
December 20, 2019 19:26
-
-
Save nyanloutre/0005a27f1545f46c114478f9949cb96f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import shutil | |
from bs4 import BeautifulSoup | |
s = requests.Session() | |
s.get("https://ae.utbm.fr/") | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0', | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
'Accept-Language': 'fr-FR,en-US;q=0.7,en;q=0.3', | |
'Origin': 'https://ae.utbm.fr', | |
'DNT': '1', | |
'Connection': 'keep-alive', | |
'Referer': 'https://ae.utbm.fr/matmatronch/', | |
'Upgrade-Insecure-Requests': '1', | |
'Pragma': 'no-cache', | |
'Cache-Control': 'no-cache', | |
'TE': 'Trailers', | |
} | |
data = { | |
'csrfmiddlewaretoken': s.cookies["csrftoken"], | |
'username': 'CODE', | |
'password': 'PASSWORD', | |
'next': '/matmatronch/' | |
} | |
response = s.post('https://ae.utbm.fr/login/', headers=headers, data=data) | |
soup = BeautifulSoup(response.content, features="html.parser") | |
form = soup.find("form", attrs={"action": "/matmatronch/"}) | |
input_csrfmiddlewaretoken = form.find("input", attrs={"name": "csrfmiddlewaretoken"}) | |
csrfmiddlewaretoken = input_csrfmiddlewaretoken["value"] | |
files = { | |
"csrfmiddlewaretoken": (None, csrfmiddlewaretoken), | |
"first_name": (None, ""), | |
"last_name": (None, ""), | |
"nick_name": (None, ""), | |
"role": (None, ""), | |
"department": (None, ""), | |
"semester": (None, ""), | |
"semester": (None, ""), | |
"date_of_birth": (None, "22/04/2001"), | |
"sex": (None, "WOMAN") | |
} | |
headers["Origin"] = "https://ae.utbm.fr/matmatronch/" | |
matmatronch = s.post("https://ae.utbm.fr/matmatronch/", headers=headers, files=files) | |
matmat_results = BeautifulSoup(matmatronch.content, features="html.parser") | |
girlz_div = matmat_results.find("div", class_="matmat_results") | |
girlz = girlz_div.find_all("div", class_="matmat_user") | |
# print(girlz) | |
for girl in girlz: | |
girl_pic_div = girl.find("div", class_="user_mini_profile_picture") | |
girl_pic = girl_pic_div.find("img") | |
pic_get = s.get("https://ae.utbm.fr" + girl_pic["src"], stream=True) | |
girl_name = girl.find("div", class_="user_mini_profile_name").get_text() | |
with open("{}.jpg".format(girl_name), 'wb') as f: | |
pic_get.raw.decode_content = True | |
shutil.copyfileobj(pic_get.raw, f) | |
print("Saved {}".format(f.name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment