Skip to content

Instantly share code, notes, and snippets.

@streetgt
Last active March 5, 2023 00:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save streetgt/5c925c5601caa3b1735f5eaf098da855 to your computer and use it in GitHub Desktop.
Save streetgt/5c925c5601caa3b1735f5eaf098da855 to your computer and use it in GitHub Desktop.
Vipon - Scraper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# used to click products given a product_id and fetch all vouchers
import requests, time
from lxml import etree
class ViponBot:
def __init__(self, email, password):
self.email = email
self.password = password
self.s = requests.Session()
self.s.headers.update = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0' }
self.login()
def login(self):
r = self.s.get( 'https://www.vipon.com/login' )
htmlObj = etree.HTML( r.text )
csrf_frontend = htmlObj.xpath('//*[@id="form-login"]/input/@value')[0]
# make the login
payload = {
'LoginForm[email]' : self.email,
'LoginForm[password]' : self.password,
'LoginForm[rememberMe]' : 1,
'_csrf-frontend' : csrf_frontend
}
r = self.s.post( 'https://www.vipon.com/login', data=payload )
def click_product(self, product_id):
url = 'https://www.vipon.com/request/index'
payload = {
'product_id' : product_id,
}
r = self.s.post( url, data=payload )
return r.text
def fetch_vouchers(self):
r = self.s.get( 'https://www.vipon.com/shopper/request' )
htmlObj = etree.HTML( r.text )
products_id = []
vouchers = []
for elem in htmlObj.xpath('//*[@id="review-table"]/tbody'):
products_id = elem.xpath('//tr/@data-product-id')
vouchers = elem.xpath('//tr/td[5]/text()')
htmlObj = etree.HTML( r.text )
remaining = htmlObj.xpath('//*[@id="review-container"]/div[1]/div/div[2]/h1/text()')
result = int(''.join(remaining)[20::]), dict(zip(products_id, vouchers))
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment