[英]My Webscraping code with beautifulsoup doesn't go past the first page
[英]my webscraping code won't let my streamlit app stop running
我正在嘗試使用流光構建一個應用程序,並且在我的代碼中我想做一些網頁抓取,將新數據添加到我的 excel 文件(csv 文件)中。 我的腳本就是這樣做的,但是當我運行應用程序時它不會停止運行,這是我的代碼:
date = datetime.date.today().strftime("%d/%m/%Y")
url = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,EUR"
response = requests.get(url).json()
price = response["USD"]
fieldnames = ["date", "price"]
with open('data.csv', 'r+') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
csv_writer.writeheader()
while True:
with open('data.csv', 'a') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
info = {
"date": date,
"price": price
}
csv_writer.writerow(info)
print(date, price)
#date = datetime.date.today()
date = datetime.date.today().strftime("%d/%m/%Y")
url = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,EUR"
response = requests.get(url).json()
price = response["USD"]
time.sleep(86400)
退出 while 循環。
不要為86400睡覺。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.