ImportError:无法导入名称'BeautifulSoup',已经安装的bs4

Abhinav库马尔

我正在从stackverflow上的一个线程尝试以下代码-使用python从网页中提取在特定单词之后的单词

我已将文件命名为s.py symantec.py之类的多种名称

from bs4 import BeautifulSoup
import requests

response = requests.get('http://vpnbook.com/freevpn')
soup = BeautifulSoup(response.text, 'html.parser')
pricing = soup.find(id = 'pricing')
first_column = pricing.find('div', {'class': 'one-third'})
for li in first_column.find('ul', {'class': 'disc'}):
    if 'password' in str(li).lower():
        password = li.find('strong').text
print(password)

我面临以下错误-

python s.py
Traceback (most recent call last):
  File "s.py", line 1, in <module>
    from bs4 import BeautifulSoup
  File "C:\Users\Abhinav\Documents\automation\bs4.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup'
马苏德

请更改文件名'bs4.py'

"C:\Users\Abhinav\Documents\automation\bs4.py"

将其更改为其他名称,因为BeautifulSoup本身正在使用bs4.py。


也只需转到安装了C:\ python \ Lib \ site-packages的python文件,然后复制bs4和beautifulsoup4-4.6.0.dist-info文件夹并将其粘贴到保存了工作项目的项目文件夹中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ImportError:无法导入名称“ BeautifulSoup4”

从bs4导入BeautifulSoup4

如何从bs4导入BeautifulSoup?

在PyCharm中“未解决”导入bs4或BeautifulSoup4。安装很好

ImportError:没有名为bs4的模块(BeautifulSoup)

ImportError:没有名为bs4的模块(BeautifulSoup)

安装iPython:“ ImportError无法导入名称路径”?

Beautifulsoup4导入错误:没有名为bs4的模块

使用BeautifulSoup ImportError在Appengine上使用Python:没有名为bs4的模块

ImportError:无法在新安装中导入名称“ opentype”

pip安装失败,并出现ImportError:无法导入名称'SourceDistribution'

ImportError:安装气流后无法导入名称“ ClassVar”

ImportError:安装Pusher后无法导入名称certificate_transparency

安装了BeautifulSoup,但仍未获得名为bs4的模块

BS4安装成功,python无法识别

为什么我安装的beautifulsoup无法导入?

无法导入请求和 bs4

安装pgAdmin4时出现“ ImportError:无法导入名称'ImmutableDict'”错误

from bs4 import BeautifulSoup4

无法安装BeautifulSoup

beautifulsoup和bs4有什么区别

使用 bs4 beautifulSoup 查找特定元素

在Python bs4中匹配beautifulsoup儿童的文本

AttributeError:模块“ bs4”没有属性“ BeautifulSoup”

在 bs4/beautifulSoup 中隔离一个属性

Python bs4 BeautifulSoup:findall 给出空括号

无法执行“ pip安装版本”并显示Python导入错误-ImportError:无法导入名称“ izip_longest”

ImportError:在已安装的应用程序中包含“注册”时,无法导入名称RequestSite

在iMac上安装Apache-Airflow-Airflow InitDB-ImportError:无法导入名称对象