Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize Articles - Not Printing #61

Closed
theshapguy opened this issue Jul 7, 2014 · 1 comment
Closed

Memoize Articles - Not Printing #61

theshapguy opened this issue Jul 7, 2014 · 1 comment

Comments

@theshapguy
Copy link

Articles not being parsed from Memoize?

import newspaper
cnn_paper = newspaper.build('http://cnn.com', memoize_articles=True)

for article in cnn_paper.articles:
    print article.url

It runs for the first time as it is not cached and prints all the results, The second time nothing is printed, -- BLANK --

@codelucas
Copy link
Owner

"It runs for the first time as it is not cached and prints all the results, The second time nothing is printed"

That is expected behavior. On the second run the data is cached but not displayed. This is because of the use case of newspaper as typically you don't want duplicate articles, with memoization on, you can extract from CNN freely without worrying about if you extracted the same article twice in a row.

If you don't like this behavior you have two options:
1.) Turn memoization off, nothing is cached but you get all the data every time.
2.) Go a step lower, instead of using newspaper.build, import Article objects directly
and choose which articles you want to cache & keep or etc.

Reference:
http://newspaper.readthedocs.org/en/latest/user_guide/quickstart.html#article-caching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants