0

I am trying to parse a webpage with Python->Beautiful Soup and the text after loading about 2seconds only appear: [1]Here is the Image about the HTML about the extract

I am trying to extract the contents of the highlighted (Sold Out).

price = soup.find('button', attrs={'class':'ncss-btn-primary-dark'})

But I have an error code with this

price = soup.find('button', attrs={'class':'ncss-btn-primary-dark  btn-lg btn-lg disabled'}).text AttributeError: 'NoneType' object has no attribute 'text'

How can I get the text Sold Out from the image shown above? Or should I need something to wait the text to show up only able to find it?

Sunkr
  • 1
  • 1

1 Answers1

0

Well nice try, .text change it as #.text and mentioned attrs={'class': 'ncss-btn-primary-dark'}.

If you are not understood please see below code in,particularly attribute.

Follow this below mentioned code it will work.

from bs4 import BeautifulSoup
s = """
<button type="button" class="ncss-btn-primary-dark  btn-lg btn-lg disabled">Sold Out</button>
"""
soup = BeautifulSoup(s, 'html.parser')

#print(soup.find('button', {'class': 'whatever class name mentioned on your code type here and try'}).text)
print(soup.find('button', {'type': 'button'}).text)

#(or) this below mentioned attribute method also working
print(soup.find('button', attrs={'type': 'button'}).text)