Post

PythonPython

S
SRINIVAS GARNEPALLI

Posted on 5th March 2024|133 views

0
votes

'NoneType' Object Is Not Subscriptable

import requests
from bs4 import BeautifulSoup

URL = 'https://www.amazon.in/Acer-15-6-inch-Graphics-Obsidian-AN515-55/dp/B088FLY29Z/ref=sr_1_2?crid=2JYW7GB0Y0EAL&dchild=1&keywords=acer+nitro+5+2020&qid=1597467216&sprefix=acer+%2Caps%2C282&sr=8-2'
headers = {'User Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content,'html.parser')
print(soup.prettify())
title = soup.find(id="productTitle")
if title:
    title1 = title.get_text
    print(title1)
price = soup.find(id="priceblock_ourprice")
if price:
    price1 = price().get_text
    print(price1)
converted_price = float(price[0:5])

print(converted_price)
  

Answers

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos