R
R
rusyska550112021-10-07 00:37:36
beautiful soup
rusyska55011, 2021-10-07 00:37:36

How to connect the html.parser library to bs4 if bs4 is installed locally in the project folder?

There is a project where the libraries folder is located, it contains libraries so that a person does not install packages when using my application.
Test code:

from libraries.beautifulsoup4.bs4 import BeautifulSoup
html = '<div> Hello! </div>'
soup = BeautifulSoup(html, 'html.parser')
print(soup.find('div'))


It throws the following error:
raise FeatureNotFound(
libraries.beautifulsoup4.bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html.parser. Do you need to install a parser library?

The problem is how bs4 looks for libraries - it asks not for the path, but for its name. This very path he somehow builds himself. I found the system library html.parser, added it, prescribed the path but it doesn’t work. I don’t understand how the route is worth.

Everything works if you run bs4 installed via pip (from bs4 import BeatufulSoup).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-10-07
@rusyska55011

If you look at the source , you can see that it has its own htmlparser, which, by the way, implies that bs4 is imported, and in general. Obviously, you need to do many, many direct imports of everything that is used there.
But I would be more careful about copying libraries - there may be binaries compiled during installation or compiled in advance for your system.
Better use pip to create requirements.txt and then

pip install -r requirements.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question