如何使用BeautifulSoup解决此命名空间冲突?

时间:2015-11-18 12:37:38

标签: python python-2.7 beautifulsoup

我在Python命名空间方面遇到了一些麻烦。

使用import bs4

>>> import bs4
>>> print type(x)
>>> <class 'bs4.element.NavigableString'>
>>> isinstance(x,bs4.element.NavigableString)
>>> True

但我想使用from bs4 import BeautifulSoup,然后我收到错误

>>> from bs4 import BeautifulSoup
>>> print type(x)
>>> <class 'bs4.element.NavigableString'>
>>> isinstance(x,bs4.element.NavigableString)
>>> ...
NameError: name 'bs4' is not defined


isinstance(x,bs4.element.NavigableString)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
             What should go here? 

同时检查了isinstance not working correctly with beautifulsoup(NameError),但它对我没有帮助。

1 个答案:

答案 0 :(得分:0)

正如@jonrsharpe所说,将导入语句替换为create table Contribution ( ContributionID int not null auto_increment, CreatedByUserId int not null, StoryID int not null, PreviousCID int, NextCID int, OriginalCID int, Content longblob not null, CreatedDate datetime not null default 'getdate()', primary key (ContributionID) ); alter table Contribution add constraint FK_CONTRIBU_REFERENCE_CONTRIBU2 foreign key (PreviousCID) references Contribution (ContributionID); alter table Contribution add constraint FK_CONTRIBU_REFERENCE_CONTRIBU3 foreign key (NextCID) references Contribution (ContributionID); alter table Contribution add constraint FK_CONTRIBU_REFERENCE_CONTRIBU4 foreign key (OriginalCID) references Contribution (ContributionID); ,将有问题的行替换为from bs4 import BeautifulSoup, element