Fehlermeldung IndexError: list index out of range
Verfasst: Sonntag 12. Mai 2019, 11:42
Hallo und Guten Tag, liebes Forum,
bin neu hier und habe ein Problem, mit dem ich ganz und gar nicht klar komme:
Folgendes Jupyter Notebook, welches auch sehr gut funktioniert:
from datetime import datetime
import bs4
import requests
from bs4 import BeautifulSoup
def parsePrice():
r=requests.get('https://finance.yahoo.com/quote/ALV.SG?p=ALV.SG')
soup=bs4.BeautifulSoup(r.text,"xml")
price=soup.find_all('div',{'class':'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text
return price
while True:
print('the current price: '+str(parsePrice()))
rst = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open("verbrauch2.csv", "a") as f:
f.write('ALV.SG'+','+rst+','+parsePrice()+'\n')
Nach ca 1000 - 1200 Durchgängen dann Abbruch mit folgender Fehlermeldung:
...
the current price: 200.30
the current price: 200.30
the current price: 200.30
the current price: 200.30
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-21-ef7611d30e04> in <module>
6
7 while True:
----> 8 print('the current price: '+str(parsePrice()))
9 rst = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
10 with open("verbrauch2.csv", "a") as f:
<ipython-input-21-ef7611d30e04> in parsePrice()
2 r=requests.get('https://finance.yahoo.com/quote/ALV.SG?p=ALV.SG')
3 soup=bs4.BeautifulSoup(r.text,"xml")
----> 4 price=soup.find_all('div',{'class':'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text
5 return price
6
IndexError: list index out of range
wo baut sich welche Liste auf ?
wo wird ein Index erstellt, den ich kontrollieren kann ?
Für jede Hilfe oder auch Tipps bin ich sehr dankbar
wovo42
bin neu hier und habe ein Problem, mit dem ich ganz und gar nicht klar komme:
Folgendes Jupyter Notebook, welches auch sehr gut funktioniert:
from datetime import datetime
import bs4
import requests
from bs4 import BeautifulSoup
def parsePrice():
r=requests.get('https://finance.yahoo.com/quote/ALV.SG?p=ALV.SG')
soup=bs4.BeautifulSoup(r.text,"xml")
price=soup.find_all('div',{'class':'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text
return price
while True:
print('the current price: '+str(parsePrice()))
rst = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open("verbrauch2.csv", "a") as f:
f.write('ALV.SG'+','+rst+','+parsePrice()+'\n')
Nach ca 1000 - 1200 Durchgängen dann Abbruch mit folgender Fehlermeldung:
...
the current price: 200.30
the current price: 200.30
the current price: 200.30
the current price: 200.30
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-21-ef7611d30e04> in <module>
6
7 while True:
----> 8 print('the current price: '+str(parsePrice()))
9 rst = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
10 with open("verbrauch2.csv", "a") as f:
<ipython-input-21-ef7611d30e04> in parsePrice()
2 r=requests.get('https://finance.yahoo.com/quote/ALV.SG?p=ALV.SG')
3 soup=bs4.BeautifulSoup(r.text,"xml")
----> 4 price=soup.find_all('div',{'class':'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text
5 return price
6
IndexError: list index out of range
wo baut sich welche Liste auf ?
wo wird ein Index erstellt, den ich kontrollieren kann ?
Für jede Hilfe oder auch Tipps bin ich sehr dankbar
wovo42