-6
from bs4 import BeautifulSoup

import requests

headers = {'Use-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/79.0.3945.130 Safari/537.36'}

url = 'https://www.amazon.com/Sony-Alpha-a6400-Mirrorless-Camera/dp/B07MV3P7M8/ref=sr_1_4?keywords=sony+alpha&qid=1581656953&s=electronics&sr=1-4'

page = requests.get(url,headers=headers)

soup = BeautifulSoup(page.content, 'html.parser')

title = soup.find(id="productTitle").get_text()

price = soup.find(id="priceblock_ourprice").get_text()

print(title)

print(price)
Kaushal28
  • 5,377
  • 5
  • 41
  • 72

1 Answers1

0

Your code works fine but there is a robot check before the product page so your request looks for the span tag in that robot check page, fails and returns None.

Here is a link which may help you: python requests & beautifulsoup bot detection

fizgi
  • 40
  • 8