@@ -19,7 +19,7 @@ Newspaper utilizes async io and caching for speed. *Also, everything is in unico
1919
2020The core 3 methods are:
2121
22- * ``download() `` retrieves the html, with non blocking io whenever possible.
22+ * ``download() `` retrieves the html, with multithreading whenever possible.
2323* ``parse() `` extracts the body text, authors, titles, etc from the html.
2424* ``nlp() `` extracts the summaries, keywords, sentiments from the text.
2525
@@ -29,7 +29,7 @@ There are two API's available. Low level ``article`` objects and ``newspaper`` o
2929
3030 >>> import newspaper
3131
32- >>> cnn_paper = newspaper.build('http://cnn.com')
32+ >>> cnn_paper = newspaper.build('http://cnn.com') # this takes 10 seconds ish
3333
3434 >>> for article in cnn_paper.articles:
3535 >>> print article.url
@@ -38,25 +38,30 @@ There are two API's available. Low level ``article`` objects and ``newspaper`` o
3838 u'http://www.cnn.com/2013/12/07/us/life-pearl-harbor/?iref=obinsite'
3939 ...
4040
41- >>> print cnn_paper.category_urls
41+ >>> print cnn_paper.size() # number of articles we extracted and cached
42+ 3100
43+
44+ # category & feed urls extracted once, then cached for a day (adjustable)
45+ >>> print cnn_paper.category_urls()
4246 [u'http://lifestyle.cnn.com', u'http://cnn.com/world', u'http://tech.cnn.com' ...]
4347
44- >>> print cnn_paper.feed_urls
48+ >>> print cnn_paper.feed_urls()
4549 [u'http://rss.cnn.com/rss/cnn_crime.rss', u'http://rss.cnn.com/rss/cnn_tech.rss', ...]
4650
4751
48- #### download html for all articles **concurrently**
49- >>> cnn_paper.download()
52+ #### build articles, then download, parse, and perform NLP
53+ >>> for article in cnn_paper.articles[:5]:
54+ article.download()
5055
5156 >>> print cnn_paper.articles[0].html
5257 u'<!DOCTYPE HTML><html itemscope itemtype="http://...'
5358
54- >>> print cnn_paper.articles[5 ].html
55- u'<!DOCTYPE HTML><html itemscope itemtype="http://...'
59+ >>> print cnn_paper.articles[7 ].html
60+ u'' # we only decided to download 5 articles
5661
5762
58- #### parse html on a per article basis **not concurrent**
59- >>> cnn_paper.articles[0].parse()
63+ ### parse an article for it's body text, top image, authors, and title
64+ >>> cnn_paper.articles[0].parse() # just one article this time
6065
6166 >>> print cnn_paper.articles[0].text
6267 u'Three sisters who were imprisoned for possibly...'
@@ -71,7 +76,7 @@ There are two API's available. Low level ``article`` objects and ``newspaper`` o
7176 u'Police: 3 sisters imprisoned in Tucson home'
7277
7378
74- #### extract nlp on a per article basis **not concurrent**
79+ #### extract nlp (must be on an already parsed article
7580 >>> cnn_paper.articles[0].nlp()
7681
7782 >>> print cnn_paper.articles[0].summary
@@ -80,22 +85,20 @@ There are two API's available. Low level ``article`` objects and ``newspaper`` o
8085 >>> print cnn_paper.articles[0].keywords
8186 [u'music', u'Tucson', ... ]
8287
88+ # not we try nlp() on an article that has not been downloaded
89+ >>> print cnn_paper.articles[100].nlp()
90+ Traceback (...
91+ ...
92+ ArticleException: You must parse an article before you try to nlpify is
93+
8394
8495 #### some other news-source level functionality
8596 >>> print cnn_paper.brand
8697 u'cnn'
8798
88- ## Alternatively, parse and nlp all articles together. Will take a while...
89- ##
90- ## for article in cnn_paper.articles:
91- ## article.parse()
92- ## article.nlp()
93- ##
94- ## You could even download() articles on a per article basis but
95- ## that becomes very slow because it wont be concurrent.
96- ##
97- ## for article in cnn_paper.articles:
98- ## article.download()
99+ >>> print cnn_paper.description
100+ u'CNN.com delivers the latest breaking news and information on the latest...'
101+
99102
100103 Alternatively, you may use newspaper's lower level Article api.
101104
@@ -117,6 +120,12 @@ Alternatively, you may use newspaper's lower level Article api.
117120 >>> print article.authors
118121 [u'Martha Stewart', u'Bob Smith']
119122
123+ >>> print article.top_img
124+ u'http://some.cdn.com/3424hfd4565sdfgdg436/
125+
126+ >>> print article.title
127+ u'Thanksgiving Weather Guide Travel ...'
128+
120129 >>> article.nlp()
121130
122131 >>> print article.summary
0 commit comments