问题描述
我目前正在编写一个脚本,该脚本可以登录到 study.com 并显示到期的作业。但我一直面临 TypeError
错误。
这是我的代码:
import requests
from bs4 import BeautifulSoup
from colorama import Fore,init
# initializing the colors
init()
init(convert=True)
# log in info
data = {
'username': 'insert email here','password': 'insert password here','remember-me': 'on'
}
# headers
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
with requests.Session() as s:
r = s.get('https://study.com/academy/login.html')
soup = BeautifulSoup(r.content,'html5lib')
data['_csrf'] = soup.find('input',attrs={'name': '_csrf'})['value']
r = s.post('https://study.com/academy/login.ajax',data=data,headers=headers)
if 'memberDashboard' in r.text:
print(Fore.GREEN + 'Logged in.')
else:
print('Error. Wrong email or password')
Traceback (most recent call last):
File "test2.py",line 25,in <module>
data['_csrf'] = soup.find('input',attrs={'name': '_csrf'})['value']
TypeError: 'nonetype' object is not subscriptable
我对 python 很陌生,所以我不知道 TypeError
错误实际上意味着什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)