Skip to content

Instantly share code, notes, and snippets.

@nisests
Last active October 26, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nisests/bc49eefbd5c9d3baa701fb06c75ea270 to your computer and use it in GitHub Desktop.
Save nisests/bc49eefbd5c9d3baa701fb06c75ea270 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':'251323229@qq.com',
'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