Log in to Slack using requests in Python

Module to use

Whole code

from bs4 import BeautifulSoup
import requests
import re

TEAM_NAME = "hoge"

payload = {
    'signin': "1",
    'email': 'email',
    'password': 'password'
}

login_url = 'https://%s.slack.com/' % TEAM_NAME

#Access the login page
session = requests.Session()
response = session.get(login_url)

#Get crumb
bs = BeautifulSoup(response.text)
auth_token = bs.find(attrs={'name': 'crumb'}).get('value')
payload['crumb'] = auth_token

#log in
session.post(login_url, data=payload)

Recommended Posts

Log in to Slack using requests in Python
Post to Slack in Python
Develop slack bot in python using chat.postMessage
Try to log in to Netflix automatically using python on your PC
How to specify TLS version in python requests
Log in to Yahoo Business with Selenium Python
Post from Python to Slack
Post to vim → Python → Slack
To flush stdout in Python
Login to website in Python
Post to slack with Python 3
Post to Twitter using Python
Start to Selenium using python
Write data to KINTONE using the Python requests module
Speech to speech in python [text to speech]
How to exit when using Python in Terminal (Mac)
How to retrieve multiple arrays using slice in python.
Implement Slack chatbot in Python
How to develop in Python
How to execute a command using subprocess in Python
Translate using googletrans in Python
Using Python mode in Processing
Try to make it using GUI and PyQt in Python
Disable SSL validation without using verify = False in Python requests
To return char * in a callback function using ctypes in Python
Get Python scripts to run quickly in Cloud Run using responder
Things to keep in mind when using Python with AtCoder
I tried to make a stopwatch using tkinter in python
Things to keep in mind when using cgi with python.
How to log in to AtCoder with Python and submit automatically
How to install python using anaconda
GUI programming in Python using Appjar
[Python] How to do PCA in Python
Retry post request using python requests
Precautions when using pit in Python
How to collect images in Python
How to use Requests (Python Library)
How to use SQLite in Python
Try using LevelDB in Python (plyvel)
In the python command python points to python3.8
[python] Copy script to generate copy log
Try to calculate Trace in Python
Using global variables in python functions
Post to slack in Go language
How to use Mysql in python
Let's see using input in python
How to wrap C in Python
How to use ChemSpider in Python
Infinite product in Python (using functools)
6 ways to string objects in Python
How to use PubChem in Python
Edit videos in Python using MoviePy
Add TRACE log level to Python ...?
Handwriting recognition using KNN in Python
Try using Leap Motion in Python
How to handle Japanese in Python
Depth-first search using stack in Python
How to log in to Docker + NGINX
An alternative to `pause` in Python
When using regular expressions in Python
GUI creation in python using tkinter 2