我想从一个网站上获取令牌,这是我的代码:
import requests
from bs4 import BeautifulSoup
class checker_start(object):
def get_token(self, bs4):
data = requests.get("https://login.live.com")
soup = bs4.BeautifulSoup(data.text, 'lxml')
token_1 = soup.find("input", {"value": "flowToken"})["value"]
return token_1
print(checker_start().get_token())
但是我收到此错误:
TypeError: get_token() missing 1 required positional argument: 'bs4'
答案 0 :(得分:0)
为什么需要将bs4参数传递给Class。 bs4已经导入。您可以尝试执行此操作
def get_token(self):
data = requests.get("https://login.live.com")
soup = BeautifulSoup(data.text, 'lxml')
token_1 = soup.find("input", {"value": "flowToken"})["value"]
return token_1
print(checker_start().get_token())