Hi all,
i am new to Python and am following examples found here
https://medium.freecodecamp.org/how-to-s...46935d93fe
to try to scrap text and prices from certain website.
It returned error although i followed the steps. Not sure what happened.
My code as per below:
<h1 class="companyName__99a4824b">S&P 500 Index</h1>
traceback:
name = name_box.text.strip # strip() is used to remove starting and trailing
AttributeError: 'NoneType' object has no attribute 'text'
Appreciate your guidance.
Thank you.
HC
i am new to Python and am following examples found here
https://medium.freecodecamp.org/how-to-s...46935d93fe
to try to scrap text and prices from certain website.
It returned error although i followed the steps. Not sure what happened.
My code as per below:
# import libraries import requests import urllib from bs4 import BeautifulSoup # specify the url quote_page='http://www.bloomberg.com/quote/SPX:IND' # query the website and return the html to the variable ‘page’ page = urllib.request.urlopen(quote_page) # parse the html using beautiful soup and store in variable `soup` soup = BeautifulSoup(page,'html.parser') # Take out the <div> of name and get its value name_box = soup.find('h1', attrs={'class':'companyName__99a4824b'}) name = name_box.text.strip # strip() is used to remove starting and trailing print (name)this the text to be scrapped
<h1 class="companyName__99a4824b">S&P 500 Index</h1>
traceback:
name = name_box.text.strip # strip() is used to remove starting and trailing
AttributeError: 'NoneType' object has no attribute 'text'
Appreciate your guidance.
Thank you.
HC