Skip to content

Instantly share code, notes, and snippets.

@cubedtear
Created March 23, 2018 14:09
Show Gist options
  • Select an option

  • Save cubedtear/e825f5eb9f77f18e40756ad8a1a14e4d to your computer and use it in GitHub Desktop.

Select an option

Save cubedtear/e825f5eb9f77f18e40756ad8a1a14e4d to your computer and use it in GitHub Desktop.

Revisions

  1. cubedtear created this gist Mar 23, 2018.
    32 changes: 32 additions & 0 deletions RataModeOn.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import requests
    from lxml import html, etree

    item_prices = []

    for page in range(1, 10):
    r = requests.get('https://www.chollometro.com/nuevos', {'page': str(page), 'ajax': 'true'})

    res = html.fromstring(r.text)
    items = res.xpath('//div[contains(@class, "threadCardLayout--card")]')
    for item in items:
    t = etree.tostring(item)
    if item.xpath('.//article[contains(@class, "thread--expired")]'):
    continue
    price_elems = item.xpath('.//span[contains(@class, "thread-price")]')
    if not price_elems:
    continue
    title_elem = item.xpath('.//strong[contains(@class, "thread-title")]/span/a')
    title = title_elem[0].text.strip()
    price = price_elems[0].text.replace("€", "").replace(",", ".")
    try:
    item_prices.append((title, float(price), title_elem[0].attrib['href']))
    except ValueError:
    pass

    item_prices.sort(key=lambda x: x[1])

    longest = len(max(item_prices, key=lambda x: len(x[0]))[0])

    for title, price, url in item_prices:
    print("{price:7} - {title:{width}s} - {url}".format(title=title, price=price, url=url, width=longest))