У меня есть код, над которым я работаю, и мне нужна была помощь в том, как запланировать еженедельное выполнение моей программы. Я также хотел экспортировать свой вывод в файл CSV и не знал, как реализовать его в коде, который у меня уже есть. Я получаю информацию об акциях от https://www.eia.gov/petroleum/ вот мой код:
# Importing needed libraries
import requests
from bs4 import BeautifulSoup
URL = "https://www.eia.gov/petroleum/" # Specifiy which URL/web page we are going to be scrapping
res = requests.get(URL).text # Open the URl using requests
soup = BeautifulSoup(res,'lxml')
for items in soup.find('table', class_='basic_table').find_all('tr')[1::1]: # Exception handling
data = items.find_all(['td']) # Use 'find_all' function to bring back all instances
try: # Looks up information in each specified data row
stocks = data[0].text
third_week = data[1].text
second_week = data[2].text
first_week = data[3].text
except IndexError:pass
print("{}| {}: {} | {}: {} | {}: {}".format(stocks, "Price in million barrels 3 weeks ago",third_week,"Price in million barrels 2 weeks ago",second_week,"Price in million barrels 1 week ago",first_week)) # Formatting my intended output