How do I use the Python newspaper library?
I am trying to make a web parser and save it. I found the newspaper library . I am using Eclipse. But I couldn't get a good result. Please help me.
import newspaper
cnn_paper = newspaper.build('http://cnn.com')
for article in cnn_paper.articles:
print(article.url)
This error message:
Traceback (most recent call last):
File "D:\workspace2\JesElaSearchSys\NespaperScraper_01.py", line 2, in <module>
import newspaper
File "C:\Python27\lib\site-packages\newspaper3k-0.1.5-py2.7.egg\newspaper\__init__.py", line 10, i
n <module>
from .article import Article, ArticleException
File "C:\Python27\lib\site-packages\newspaper3k-0.1.5-py2.7.egg\newspaper\article.py", line 12, in
<module>
from . import images
File "C:\Python27\lib\site-packages\newspaper3k-0.1.5-py2.7.egg\newspaper\images.py", line 15, in
<module>
import urllib.request
ImportError: No module named request
source to share
While there is already an answer, the newspaper library for Python2 is deprecated and should be avoided.
Newspaper is out of date for Python2 and this is a buggy version according to the official documentation . You should switch to Python3 version.
Installation in Python 3:
pip3 install newspaper3k
Newspaper is a Python3 library! Or check out our outdated and sloppy Python2 branch. Run: pip3 install newspaper3k and NOT pip3 install newspaper. On python3, you have to install newspaper 3k, not newspaper. newspaper is our python2 library. While newspaper installation is straightforward with pip, you will run into fixable issues if you try to install on ubuntu.
source to share