import requests
from bs4 import BeautifulSoup
URL="https://shop.beobasta.rs/proizvod/smrznuti-spanac/"
header={"User Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OPR/105.0.0.0","Accept-Language":"en-US,en;q=0.9"}
response=requests.get(URL,headers=header)
soup=BeautifulSoup(response.text,'html.parser')
price_element = soup.find("span",class_="woocommerce-Price-amount amount")
print(price_element)
I’m trying to extract price from this website but the only thing I’m getting is None. What am I doing wrong?
2
Answers
If you check your soup with:
This is because in
requests.get(URL,headers=header)
your header is not compatible with that website.If you for example would just use:
requests.get(URL)
it would probably work already.It has to be
User-Agent
, notUser Agent
– and this makes all problem.But code works also without
User-Agent
.Or even with fake
"User-Agent": "Mozilla/5.0"