1

I'm trying to recreate the web scraping on this website

https://medium.freecodecamp.org/how-to-scrape-websites-with-python-and-beautifulsoup-5946935d93fe

I'm working in jupyter as a first project and I've come up with this error

AttributeError: 'NoneType' object has no attribute 'text'

I've tried changing the link but it makes no difference. I don't really know enough to do anything about the problem. Here is all the code so far...

#import the libraries
import urllib.request
from bs4 import BeautifulSoup
# specify the url
quote_page = "https://www.bloomberg.com/quote/SP1:IND"
page = urllib.request.urlopen(quote_page)
# parse the html using BeautifulSoup 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": "name"})
name = name_box.text.strip() 
# strip() is used to remove starting and trailing
print (name)
# get the index price
price_box = soup.find("div", attrs={"class":"price"})
price = price_box.text.strip()
print (price)

Any help would be appreciated a lot

1 Answer 1

0

I use selenium to webscrape, but I am sure I can help you out (maybe).
This section is were you code gives you the error I assume:

price_box = soup.find("div", attrs={"class":"price"})
price = price_box.text.strip()
print (price)

What I would do is:

price_box = soup.find("div", attrs={"class":"price"})
price = price_box().text
print (price.text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.