Last active
December 2, 2022 16:58
-
-
Save Cheaterman/7ad9681ab7b9854816a66b7c43d65080 to your computer and use it in GitHub Desktop.
scibs.py
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 re | |
import httpx | |
from bs4 import BeautifulSoup | |
EMAIL = '[email protected]' | |
USER_AGENT = ( | |
'Mozilla/5.0 (X11; Linux x86_64; rv:99.0) ' | |
'Gecko/20100101 Firefox/99.0' | |
) | |
HOST = 'www.vacances-scientifiques.com' | |
URI = f'https://{HOST}' | |
URL = f'{URI}/01-decembre-2022.html?lang=fr' | |
session = httpx.Client(headers={'User-Agent': USER_AGENT}) | |
data = session.get(URL).text | |
soup = BeautifulSoup(data, 'html.parser') | |
# XXX: Assuming a single POST form on the page | |
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' | |
): | |
# Change the above check depending on the answers you want to give | |
continue | |
if name == 'email_1': | |
value = EMAIL | |
files.append((name, (None, value, None))) | |
response = session.post(URL, files=files) | |
response_soup = BeautifulSoup(response.text, 'html.parser') | |
# If this assertion fails, most likely the submission failed too | |
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