Skip to content

Instantly share code, notes, and snippets.

@alaingilbert
Created November 14, 2012 04:36
Show Gist options
  • Save alaingilbert/4070276 to your computer and use it in GitHub Desktop.
Save alaingilbert/4070276 to your computer and use it in GitHub Desktop.
Get a pdf on seao.ca
#! /usr/bin/python
# INSTALLATION:
# pip install requests
# pip install beautifulsoup4
from bs4 import BeautifulSoup
import os
import requests
USER = ''
PASW = ''
# Create a session (will keep the cookies)
s = requests.session()
# Get the home page (needed for the validation token)
res = s.get('https://seao.ca/index.aspx').text
soup = BeautifulSoup(res)
data = {'Login1:loginButton': 'Enter',
'Login1:passwordTextBox': PASW,
'Login1:usernameTextBox': USER,
'UCFooterMenu1:WiseScroll1': '',
'UCOpportunitySearch1:txtSearchInput': '',
'__EVENTARGUMENT': '',
'__EVENTTARGET': '',
'__EVENTVALIDATION': soup.find(id='__EVENTVALIDATION').get('value'),
'__VIEWSTATE': '',
'__VIEWSTATE_SERSIDE': 1,
}
# Login
s.post('https://seao.ca/index.aspx', data)
# Get and write a pdf file
with open('tmp.pdf', 'w+') as f:
f.write(s.get('https://seao.ca/GenericComponents/CUG10/viewFile.aspx?itemid=a18c621b-9bce-49ee-8eeb-d43c924bc3df').content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment