Я хочу использовать BeautifulSoup для просмотра веб-страниц.Я установил BeautifulSoup4 с pip, и у меня есть версия Python 3.6.Это мой код:
import requests
from bs4 import BeautifulSoup
url = 'https://en.wikipedia.org/wiki/Main_Page'
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
И ошибка, которую я получаю:
Traceback (most recent call last):
File "<ipython-input-65-43556f5c0560>", line 1, in <module>
soup = BeautifulSoup(html_doc, "html.parser")
File "C:\Users\WH437EQ\AppData\Local\Continuum\anaconda3\lib\site-packages\bs4\__init__.py", line 241, in __init__
self.builder.initialize_soup(self)
AttributeError: 'HTMLParserTreeBuilder' object has no attribute 'initialize_soup'
Также я попытался:
soup = BeautifulSoup(html_doc, "html5lib")
, и я получил ошибку:
Traceback (most recent call last):
File "<ipython-input-72-e6a35e1f6f46>", line 1, in <module>
soup = BeautifulSoup(html_doc, "html5lib")
File "C:\Users\WH437EQ\AppData\Local\Continuum\anaconda3\lib\site-packages\bs4\__init__.py", line 241, in __init__
self.builder.initialize_soup(self)
AttributeError: 'HTML5TreeBuilder' object has no attribute 'initialize_soup'
, а также с lxml:
soup = BeautifulSoup(html_doc, "lxml")
И я получил:
Traceback (most recent call last):
File "<ipython-input-73-0c396f083390>", line 1, in <module>
soup = BeautifulSoup(html_doc, "lxml")
File "C:\Users\WH437EQ\AppData\Local\Continuum\anaconda3\lib\site-packages\bs4\__init__.py", line 197, in __init__
builder = builder_class()
File "C:\Users\WH437EQ\AppData\Local\Continuum\anaconda3\lib\site-packages\bs4\builder\_lxml.py", line 105, in __init__
self.nsmaps = [self.DEFAULT_NSMAPS_INVERTED]
AttributeError: 'LXMLTreeBuilder' object has no attribute 'DEFAULT_NSMAPS_INVERTED'
Почему я получаю эту ошибку?