Reputation: 333
I am trying to create a dataframe which can showing and update data on the dataframe. I find this method to create a loop and output the data, it looks like this:
from bs4 import BeautifulSoup
import requests
import pandas as pd
def priceTracker():
url = 'https://finance.yahoo.com/quote/AAPL'
response = requests.get(url)
soup = BeautifulSoup(response.text,'lxml')
price = soup.find_all('div',{'class':'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text
print(price)
while True:
priceTracker()
I want to create a dataframe to store the output and using loop function which can update the data in the row, may I know is there has solution to fix it?
Upvotes: 0
Views: 58
Reputation: 24314
Why loop? when you can use read_html()
method:
import pandas as pd
data=pd.read_html('https://finance.yahoo.com/quote/AAPL')
Finally use concat()
method:
result=pd.concat(data)
Upvotes: 1