Я новичок в python. Я создал программу, которая берет новости из Google News и сохраняет их в блокноте Excel. Мне было интересно, как я могу поддерживать эту программу бесконечно и продолжать записывать новости в прямом эфире? Например, он будет продолжать хранить информацию в таблице Excel на завтра, послезавтра и т. Д. c. Мой код ниже. Большое спасибо. Я также думал, может быть, включить в него mysql и использовать его в качестве базы данных, но я еще не уверен на 100%, как это сделать.
# Web Scraping App to find Top Stories
# Importing Python Libraries
import bs4
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
from openpyxl import Workbook
# Initializing the website in rss format
url ="https://news.google.com/news/rss"
# Sending request to open the website
urlopener=urlopen(url)
# Reading the website and setting it to a variable
xml =urlopener.read()
# Closing the function
urlopener.close()
# Parsing the xml page using Beautiful Soup
souped_page = soup(xml, 'xml')
# Finding the 'item' or title of the news
news_list = souped_page.findAll('item')
# Creating empty lists to store information
titlelist =[]
linklist = []
datelist = []
# Appending all the required information to the corresponding list
for news in news_list:
titlelist.append(news.title.text)
linklist.append(news.link.text)
datelist.append(news.pubDate.text)
# Creating an excel document for the news
workbook = Workbook()
sheet = workbook.active
# Initializing variables to write to the excel document
count = 2
listindex1 = 0
# Initializing titles for the document
sheet['A1'].value = 'News'
sheet['B1'].value = 'News_Link'
sheet['C1'].value = 'Time_of_News'
# Iterating through each item in the list
for title in titlelist:
sheet['A'+ str(count)].value = titlelist[listindex1]
sheet['B' + str(count)].value = linklist[listindex1]
sheet['C' + str(count)].value = datelist[listindex1]
count+=1
listindex1+=1
# Saving the information
workbook.save(filename='top_news_formatted.xlsx')