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)
Asked
Active
Viewed 88 times
-6

Kaushal28
- 5,377
- 5
- 41
- 72

Pradeep Sharma
- 1
- 2
-
2Have you done any debugging? What specifically is the issue? – AMC Feb 14 '20 at 05:30
-
I did no debugging. It is returning None at line `soup.find(id="productTitle")` – Pradeep Sharma Feb 14 '20 at 05:35
-
1_I did no debugging._ https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – AMC Feb 14 '20 at 05:36
1 Answers
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