Last active
December 2, 2022 16:58
Revisions
-
Cheaterman revised this gist
Dec 2, 2022 . 1 changed file with 14 additions and 30 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,21 @@ import re import httpx from bs4 import BeautifulSoup EMAIL = 'some@email.com' 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 = [] @@ -25,37 +31,15 @@ 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') -
Cheaterman revised this gist
Dec 2, 2022 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ 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 @@ -54,6 +54,7 @@ }, ).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') -
Cheaterman created this gist
Dec 2, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ 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 = 'thecman@mt2015.com' files.append((name, value)) prepared = requests.Request( 'POST', URL, 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) response = session.send(prepared) response_soup = BeautifulSoup(response.text, 'html.parser') assert not response_soup.find('form', method='post')