Last active
December 2, 2022 16:58
-
-
Save Cheaterman/7ad9681ab7b9854816a66b7c43d65080 to your computer and use it in GitHub Desktop.
scibs.py
This file contains hidden or 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 re | |
import requests | |
from bs4 import BeautifulSoup | |
HOST = 'www.vacances-scientifiques.com' | |
URI = f'https://{HOST}' | |
URL = f'{URI}/01-decembre-2022.html?lang=fr' | |
session = requests.Session() | |
data = session.get(URL).text | |
soup = BeautifulSoup(data, 'html.parser') | |
form = soup.find('form', method='post') | |
files = [] | |
for input in form.find_all('input'): | |
name = input.attrs.get('name') | |
if not name: | |
continue | |
value = input.attrs.get('value', '') | |
if ( | |
name == 'checkbox_1[]' | |
and value == 'choix2' | |
): | |
continue | |
if name == 'email_1': | |
value = '[email protected]' | |
files.append((name, value)) | |
prepared = requests.Request( | |
'POST', | |
URL + '#formulaire_formidable-65', | |
files=files, | |
headers={ | |
# Some of these are probably automatic, just figured I'd do as much like the browser as possible | |
'Host': HOST, | |
'Origin': URI, | |
'Referer': URL, | |
# Added a bunch of random headers, probably only one (or a few) of them is useful | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0', | |
'Cookie': 'adv_search_mode=1; wishlist=0', | |
'Upgrade-Insecure-Requests': '1', | |
'Sec-Fetch-Dest': 'document', | |
'Sec-Fetch-Mode': 'navigate', | |
'Sec-Fetch-Site': 'same-origin', | |
'Sec-Fetch-User': '?1', | |
'Pragma': 'no-cache', | |
'Cache-Control': 'no-cache', | |
}, | |
).prepare() | |
prepared.body = re.sub(b'; filename=.*', b'', prepared.body) | |
prepared.headers['Content-Length'] = str(len(prepared.body)) | |
response = session.send(prepared) | |
response_soup = BeautifulSoup(response.text, 'html.parser') | |
assert not response_soup.find('form', method='post') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment