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

      

+3


source to share


2 answers


There is nothing wrong with the code. You will need to install or find libraries newspaper

and request

. It seems the library newspaper

/ is request

missing on your development machine.

$ pip install newspaper
$ pip install urllib3

      



The command above will help you install it.

+2


source


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.

0


source







All Articles