Created
March 10, 2020 23:13
-
-
Save jbylund/1d697818114bd8f112fba570ee09c1b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import json | |
import time | |
import cfscrape | |
import bs4 | |
def get_args(): | |
pass | |
def text_dollars_to_float(istr): | |
istr = istr.strip("\n$ ") | |
istr = istr.replace(",", "") | |
return float(istr) | |
def get_jomadeals(): | |
scraper = cfscrape.create_scraper() | |
oops = None | |
for _ in range(3): | |
try: | |
response = scraper.get("https://www.jomashop.com/jomadeals.html") | |
response.raise_for_status() | |
break | |
except Exception as oops: | |
time.sleep(1) | |
else: | |
raise oops | |
parsed = bs4.BeautifulSoup(response.content, features="html5lib") | |
cat_view = parsed.find(attrs={"class": "category-view"}) | |
price_links = cat_view.find_all("a", attrs={"class": "price-link"}) | |
results = [] | |
for iprice in price_links: | |
img = iprice.parent.parent.find("img") | |
prices = [ | |
text_dollars_to_float(p.text) for p in | |
iprice.find_all("span", attrs={"class": "price"}) | |
] | |
row = { | |
"img": img["data-original"], | |
"href": iprice.parent.find("a")["href"], | |
"regular_price": max(prices), | |
"sale_price": min(prices), | |
"title": img["alt"], | |
} | |
words = set(row["title"].lower().split()) | |
if words & set(["ladies", "sunglasses"]): | |
continue | |
results.append(row) | |
return results | |
def main(): | |
deals = get_jomadeals() | |
print(json.dumps(deals, indent=4, sort_keys=True)) | |
if "__main__" == __name__: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment