这是一段代码:
def prepare_security_questions(self, response: requests.Response) -> dict[str, str]:
soup = BeautifulSoup(response.text, 'html.parser')
form: dict[str, Any] = {}
soup_forms = soup.find_all('form')
soup_form = None
for soup_possible_form in soup_forms:
name = soup_possible_form.get('name')
问题是,当我检查soup_possible_form
的类型时,Pylance显示它是一个不正确的PageElement
对象,它应该是一个Tag
对象,并且因为name = soup_possible_form.get('name')
被标记为错误,因为根据Pylance消息:
Cannot access member "get" for type "PageElement"
Member "get" is unknown Pylance(reportGeneralTypeIssues)
我正在做一个项目,我大量使用BeautifulSoup,我不想在每次find_all -> ResultSet
迭代中都使用# type: ignore
好的,我找到了一个可能的解决方案,在所有以下代码之前,我检查了每个元素的类型:
但我对其他解决方案持开放态度
相关问题 更多 >
编程相关推荐