我正在从stackverflow的一个线程上尝试以下代码-Extract a word that follows a particular word from a webpage with 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'
答案 0 :(得分:0)
请更改文件名为'bs4.py'。
"C:\Users\Abhinav\Documents\automation\bs4.py"
将其更改为其他名称,因为BeautifulSoup本身正在使用bs4.py。
也只需转到安装了python文件的C:\ python \ Lib \ site-packages,然后复制bs4和beautifulsoup4-4.6.0.dist-info文件夹并将其粘贴到保存了您的项目文件夹中您的工作项目。