0

I want to check the price of a item from bestbuy website, however, the access is denied. Does anyone have some advice how to access? Thanks!

My code:

import requests
import bs4 as bs 

url = "https://www.bestbuy.com/site/lg-65-class-oled-b9-series-2160p-smart-4k-uhd-tv-with-hdr/6360611.p?skuId=6360611"
url_get = requests.get(url)
soup = bs.BeautifulSoup(url_get.content, 'lxml')

with open('url_bestbuy.txt', 'w', encoding='utf-8') as f_out:
    f_out.write(soup.prettify())

js_test = soup.find('span', id ='priceblock_ourprice') 
if js_test is None: 
    js_test = soup.find('span', id ='div.price-block')         
str = "" 
for line in js_test.stripped_strings : 
    str = line 

# convert to integer 
str = str.replace(", ", "") 
str = str.replace("$", "") 

current_price = int(float(str)) 
your_price = 2000
if current_price < your_price : 
    print("I can afford it") 
else: 
    print("Price is high please wait for the best deal") 

You don't have permission to access "http://www.bestbuy.com/site/lg-65-class-oled-b9-series-2160p-smart-4k-uhd-tv-with-hdr/6360611.p?" on this server.

hellokitty
  • 23
  • 6
  • As it states "You don't have permission to access". – Vishnudev Krishnadas Nov 02 '19 at 17:39
  • 1
    Since this URL works when I click it, they are probably filtering the user-agent to prevent people from scraping the site. It's not hard to bypass, but I'm going to have to leave that as an exercise to the reader. – Chuck Adams Nov 02 '19 at 22:24
  • Possible duplicate of [How to use Python requests to fake a browser visit?](https://stackoverflow.com/questions/27652543/how-to-use-python-requests-to-fake-a-browser-visit) – John Zwinck Nov 03 '19 at 02:28
  • thanks! I tried 'UserAgent' to add headers, however, another error: 286 except OpenSSL.SSL.ZeroReturnError as e: OSError: (60, 'ETIMEDOUT') During handling of the above exception, another exception occurred: --> 285 raise SocketError(str(e)) 286 except OpenSSL.SSL.ZeroReturnError as e: ProtocolError: ('Connection aborted.', OSError("(60, 'ETIMEDOUT')",)) – hellokitty Nov 03 '19 at 14:18

0 Answers0