0

I need to gather the text of the articles from multiple URLs. Code functions perfectly when entered. However, by re-entering print(first_article.text) for exporting the output to CSV only the first article appears. Is there a reason why this is happening and how would it be possible to export the text from all files?

import newspaper
from newspaper import Article

lista = ['url','url']

for list in lista:
   first_article = Article(url="%s" % list, language='en')
   first_article.download()
   first_article.parse()
   print(first_article.text)
#This prints all articles

print(first_article)
#This prints only one

Reference: Downloading articles from multiple urls with newspaper

SinTT
  • 3
  • 2
  • Could you post the code you are using to try to export it to csv? – Polkaguy6000 Jan 04 '19 at 20:10
  • @Polkaguy6000 I edited the post so it's a bit more clear - all content simply disappears at the second go. PS the issue starts already before exporting – SinTT Jan 04 '19 at 20:34
  • @Polkaguy6000 Thank you! It is extremely helpful! Do you by any chance know whether those articles can be separated into separate cells? Sorry for so many questions, just thought you might know as you managed to solve it so easily. – SinTT Jan 04 '19 at 22:25

1 Answers1

0

I think I see the problem. You want to get a list of articles. You can achieve this by appending a list:

 lista = ['url','url']
 articles = [] #initialize a list
 for list in lista:
    first_article = Article(url="%s" % list, language='en')
    first_article.download()
    first_article.parse()
    articles += [first_article.text] # Add article to list
    print(first_article.text)

 print(articles) #Print all articles
Polkaguy6000
  • 1,150
  • 1
  • 8
  • 15