如何使用Python请求将“请求有效载荷”发布到API?

时间:2020-02-12 16:37:41

标签: python post web-scraping python-requests http-post

我仍在尝试摆脱401错误,每次尝试将登录数据发布到网站时都会遇到错误。希望有人可以帮助我解决此问题:)谢谢您的帮助!

这是我的代码:

import requests
from bs4 import BeautifulSoup
import urllib
import json

email = "xxx"
password = "xxxx"

loginURL = "https://www.skatedeluxe.com/login.php"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like 
Gecko) Chrome/80.0.3987.87 Safari/537.36'}

loginCreds = {"email":email,"password":password}

#Create Session
s = requests.Session()

#Generate Cookies With GET Request
s.get(loginURL, headers=headers)

#Scrape Token
resForToken = s.post(loginURL, headers = headers)
soupForToken = BeautifulSoup(resForToken.text,"html.parser")
token = soupForToken.find("html")['data-token']

#URL For POST Request
loginPOST = "https://www.skatedeluxe.com/api2/auth?token=" + token

#POST Login Data
r = s.post(loginPOST, headers=headers, data=loginCreds)
print(r)

0 个答案:

没有答案