So I've been trying to get Beautifulsoup4 to work on both Eclipse IDE and PyCharm IDE. I've uninstalled the former before I installed the latter and then I installed (successfully) Beautifulsoup4 into the scripts folder of my current version of python. Wondering why PyCharm IDE will not recognize the code 'from bs4 import BeautifulSoup' and is currently greyed out, showing the there is no module. Has anyone else had this issue running this particular module on PyCharm? I have also tried installing it through the PyCharm settings tool in what seems to no avail.
If the package
from bs4 import BeautifulSoup
is greyed out this means that you have successfully installed the BeautifulSoup package on the PyCharm IDE, but you haven't used it in your program.
To use the package you have to follow three steps:
- Step 1:
For reference paste this link... https://www.pythonscraping.com/pages/warandpeace.html
url = "Paste the given link here"
url is the variable you are storing the website URL.
- Step 2:
Now you have open the URL which you want to access and which you have stored in the URL variable earlier.
For opening the URL you have to import a package... which is
from urllib.request import urlopen
Now you have to do this step:
HtmlContent = urlopen(url)
In above line
HtmlContent is a variable where you will store the opened URL HTML data.
- Step 3:
Now to use the BeautifulSoup package you have to create an object... below is the way to access the BeautifulSoup...
soup = BeautifulSoup(HtmlContent.read(), "lxml")
In above line
"lxml" is an HTML parser which you have install in PyCharm terminal... below is the command...
# pip install lxml
So this is the way you can access the BeautifulSoup package in you PyCharm IDE
For more further details on BeautifulSoup you can access it through this link: https://www.crummy.com/software/BeautifulSoup/bs4/doc/