I am trying to use beautifulsoup compatible lxml and it is giving me an error:
from lxml.html.soupparser import fromstring
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/lxml/html/soupparser.py", line 7, in <module>
from BeautifulSoup import \
ImportError: No module named BeautifulSoup
I have bs4 installed. How do I fix this issue?
The error is caused by soupparser.py trying to import BeautifulSoup version 3 while you have version 4 installed. The module name was changed from BeautifulSoup to bs4 in version 4.
You can trick soupparser.py into importing version 4 by mapping the bs4 module to BeautifulSoup in sys.modules before importing soupparser:
import sys, bs4
sys.modules['BeautifulSoup'] = bs4
from lxml.html.soupparser import fromstring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With