从bs4导入*无法导入Python3下的类NavigableString
我正在阅读“Beauty Soup 4.0.0文档” 遇到导入问题:从bs4导入*无法导入Python3下的类NavigableString,python,import,Python,Import,我正在阅读“Beauty Soup 4.0.0文档” 遇到导入问题: 我在python3下导入bs4(BeautifulSoup4.0)中的所有内容: from bs4 import * 但未能使用类NavigableString: >>> help(NavigableString) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameErr
我在python3下导入bs4(BeautifulSoup4.0)中的所有内容:
from bs4 import *
但未能使用类NavigableString:
>>> help(NavigableString)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'NavigableString' is not defined
但是,NavigableString和BeautifulSoup都包含在bs4的命名空间中:
>>> import bs4
>>> dir(bs4)
['BeautifulSoup',
'BeautifulStoneSoup', 'CData', 'Comment',
'DEFAULT_OUTPUT_ENCODING', 'Declaration', 'Doctype',
'NavigableString',
'PageElement', 'ProcessingInstruction', 'ResultSet', 'SoupStrainer',
'StopParsing', 'Tag', 'UnicodeDammit', '__all__', '__author__',
'__builtins__', '__cached__', '__copyright__', '__doc__', '__file__',
'__license__', '__name__', '__package__', '__path__', '__version__',
'builder', 'builder_registry', 'dammit', 'element', 're', 'syntax_error',
'warnings']
我知道我可以通过以下方式使用Navigablesting:
from bs4 import NavigableString
我很困惑,想弄清楚潜在的机制。它是否与python包或模块层次结构有关?
还是之前的进口声明
from bs4 import *
<代码> BS4..Al.Aux<<代码>,这将是唯一的名称,将从“代码> BS4导入。
<代码> BS4..Y-AlLux,因此这是唯一的名称,将从<代码> BS4导入。
切线备注:考虑不使用<代码>导入*/COD>,永远。它混淆了像pyflakes
这样的工具,并降低了代码的可读性。(我不明白为什么他们没有在Python 3中删除它)使用:从BS4导入导航字符串,标签< /代码>(等等):<代码>导入BS4< /代码>或代码>。切线备注:考虑不要使用<代码>导入*/COD>。它混淆了像pyflakes
这样的工具,并降低了代码的可读性。(我不明白为什么他们没有在Python 3中删除它。)改用:import bs4
或from bs4 import navigablesting、Tag
(等等)。
from bs4 import *