我正在从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] 删除。
我来说两句