4

I'm trying to make web parser and saved it. I had found the newspaper library. I'm using Eclipse. But I couldn't get good result. Please help me.

import newspaper

cnn_paper = newspaper.build('http://cnn.com')

for article in cnn_paper.articles:
    print(article.url)

This is a 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
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Steve
  • 43
  • 1
  • 4
  • This should help: http://stackoverflow.com/questions/24652074/importerror-no-module-named-request – fenceop Jun 04 '15 at 13:58

2 Answers2

3

There is nothing wrong with your code. You will need to install or locate the newspaper and requestlibraries. It seems newspaper / request library is missing on your development machine.

$ pip install newspaper
$ pip install urllib3

Command above will help you to install it.

Pralhad Narsinh Sonar
  • 1,406
  • 1
  • 14
  • 23
1

Though there is already an answer, the newspaper library for Python2 is deprecated and should be avoided.

Newspaper has been deprecated for Python2 and it's a buggy version according to their official documentation. You should switch to Python3 version.

Installation on Python 3:

pip3 install newspaper3k

Newspaper is a Python3 library! Or, view our deprecated and buggy Python2 branch. Run : pip3 install newspaper3k and NOT pip3 install newspaper. On python3 you must install newspaper3k, not newspaper. newspaper is our python2 library. Although installing newspaper is simple with pip, you will run into fixable issues if you are trying to install on ubuntu.

utengr
  • 3,225
  • 3
  • 29
  • 68