hi i was scraping yahoo finance and somehow the if did not work.What the if was suppose do was to print the stock price if the stock price was greater than 50 but it printed all the stocks which were above 50 and below 50 here is the code
import urllib2
from bs4 import BeautifulSoup as bs4
list = ["aapl","goog","yhoo"]
i = 0
while i < len(list):
url = urllib2.urlopen("http://ift.tt/Jz88mB"+ list[i] +"&q1=1")
soup = bs4(url,"html.parser")
for price in soup.find(attrs={'id':"yfs_l84_" + list[i]}):
if price > 50:
print price
i += 1
else:
print "failed"
1 += 1
why did it print the stock "yhoo"?? cause yahoo is less than 50 no?
Aucun commentaire:
Enregistrer un commentaire