Skip to content

Commit

Permalink
added cabelas reader
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Dec 24, 2023
1 parent 73a9e25 commit fcc6e19
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/readers/cabelas_ca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import random
import requests
import re

SITE = 'www.cabelas.ca'

agents = [
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.115 Safari/537.36'
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
]


def get_price(url: str) -> float:
agent = random.choice(agents)
r = requests.get(url, headers={'User-Agent': agent }, timeout=10)
html = r.text
pattern = r'price: (\d+\.\d+)'
matches = re.findall(pattern, html)
price = matches[0]
return float(price.strip().strip('$').strip())

0 comments on commit fcc6e19

Please sign in to comment.