-
Notifications
You must be signed in to change notification settings - Fork 95
Cannot see lxml parser for Beautiful Soup, even after pip install #1299
Answered
by
margaretkennedy
margaretkennedy
asked this question in
Q&A
Problem: Cannot see lxml parser for Beautiful Soup, even after pip install
If you have already imported the bs4 module before installing lxml, bs4 will not see lxml in the list of available parsers.
On the first import of bs4, the initialization of the module occurs, loading all existing parsers. This initialization does not re-occur after future pip installs.
To confirm what parsers bs4 is able to see, run:
import bs4
print(bs4.builder.builder_registry.builders)
Example output where lxml is NOT recognized:
[<class 'bs4.builder._htmlparser.HTMLParserTreeBuilder'>]
Example output where lxml IS recognized:
[<class 'bs4.builder._lxml.LXMLTreeBuilder'>, <class 'bs4.builder._lxml.LXMLTreeBuilderForXML'>, <class 'bs4.builder._htmlparser.HTMLParserTreeBuilder'>]
All reactions
Answered by
margaretkennedy
Sep 16, 2021
This is a known issue.
Solution:
- Restart Docker container:
docker-compose down
docker-compose up -d
- Install both Python modules before running an import on bs4.
For example:
import os
os.system("pip install bs4 lxml")
import bs4
print(bs4.builder.builder_registry.builders)
Replies: 1 comment
This is a known issue.
Solution:
- Restart Docker container:
docker-compose down
docker-compose up -d
- Install both Python modules before running an import on bs4.
For example:
import os
os.system("pip install bs4 lxml")
import bs4
print(bs4.builder.builder_registry.builders)
All reactions
0 replies
Answer selected by
rachelmbrubaker
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment