0
from bs4 import BeautifulSoup
import requests
import time
import datetime
import smtplib

URL = 'https://www.myntra.com/casual-shoes/highlander/highlander-men-white-sneakers/11097156/buy'

page = requests.get(URL, headers=headers)
soup1 = BeautifulSoup(page.content, "html.parser")
soup2 = BeautifulSoup(soup1.prettify(), "html.parser")
title = soup2.find(id='pdp-name').get_text()
price = soup2.find(id='pdp-price').get_text()
print(title)
print(price)

output:- AttributeError: 'NoneType' object has no attribute 'get_text'

Chris
  • 26,361
  • 5
  • 21
  • 42
  • 1
    You're calling `get_text()` on the result of `soup2.find(id='pdp-name')` and `soup2.find(id='pdp-price')` - so, apparently one of them doesn't find anything, returns `None` and you cannot call `.get_text()` on None. When sharing an error message, share the entire stack trace, so people can see where the error occurred. Also note that the error does not occur when you "compile", but when you *run*, that's not the same thing. – Grismar Jun 28 '22 at 23:52

1 Answers1

1

pdp-name appears to be a class in the page you're looking at, but not an id.

Consequently soup2.find(id='pdp-name') returns None which you are trying to call get_text on, resulting in the error you're seeing.

The same would seem to hold true for pdp-price as well.

Chris
  • 26,361
  • 5
  • 21
  • 42