0

import requests



url= 'https://finance.yahoo.com/quote/INTC'
html=requests.get(url)
soup = bs(html.text, 'html.parser')

price = soup.find('span',{'class': 'Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)'}).text
print('Ending price is: ', price)

PER_quote_summary = soup.find('table',{'class':'W(100%) M(0) Bdcl(c)'}).find_all('span')[5].text
print('PER of stock INTC is: ',PER_quote_summary)

if PER_quote_summary <= '30.00':
    print('Nice PER')
else:
    print('PER maybe too high.')

this is my script.

the problem is in the last 'if' part. I've got beautiful soup to parse through html and get a certain number. In this case it will be the PER of a stock.

But, Only INTEL doesn't go right.

INTEL's current PER is 9.5 and it appears on the terminal as it is, but the if statement goes wrong. The script prints out 'PER maybe too high' when it should print 'Nice PER'.

I've tried other stocks such as apple or facebook and they all go with no problem.

Why is this problem happening?

0 Answers0