Last active
October 26, 2017 07:15
-
-
Save nisests/bc49eefbd5c9d3baa701fb06c75ea270 to your computer and use it in GitHub Desktop.
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
#!/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