Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hnuzhoulin/2c79ceb48ddc79cd4a123d58fae18fdd to your computer and use it in GitHub Desktop.
Save hnuzhoulin/2c79ceb48ddc79cd4a123d58fae18fdd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
__author__ = 'Nisests'
import requests
from bs4 import BeautifulSoup
login_url = 'https://www.packtpub.com/'
accout_url = 'https://www.packtpub.com/account'
headers = {
'referer':'https://www.packtpub.com/',
'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36'
}
s = requests.session()
data = s.get(login_url,headers=headers)
# print(data.text)
soup = BeautifulSoup(data.text,'html.parser')
form_build_id = soup.find('input',attrs={'name':'form_build_id'})['value']
# print(form_build_id)
data = {
'email':'[email protected]',
'password':'1qaz2wsx3edc',
'op':'Login',
'form_build_id':form_build_id,
'form_id':'packt_user_login_form'
}
s.post(login_url,headers=headers,data=data)
# test
accout = s.get(accout_url,headers=headers)
print(accout.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment