diff --git a/app/readers/cabelas_ca.py b/app/readers/cabelas_ca.py new file mode 100644 index 0000000..bec869f --- /dev/null +++ b/app/readers/cabelas_ca.py @@ -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())