Create a gist now

Instantly share code, notes, and snippets.

@nikop /cdon.py
Last active Dec 17, 2015

What would you like to do?
CDON Varastosaldo
import urllib, urllib.request
import http, http.cookiejar
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("id")
args = parser.parse_args()
m3 = re.search('(\d+)$', args.id)
o = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()))
data = {
'productId': m3.group(1),
'quantity': 10000,
'type': 'json',
'ticket': 'null',
}
post = urllib.parse.urlencode(data).encode('utf-8')
r = o.open('http://cdon.fi/CartUpdate/Add/', post)
t = r.read().decode('utf-8')
c = o.open('http://cdon.fi/order/checkout')
t2 = str(c.read().decode('utf-8'))
m = re.search('input type="hidden" name="product-quantity-(\d+)" value="(\d+)"', t2)
m2 = re.search('(\d+)">([^<]+)</a>', t2)
print(m2.group(2), m.group(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment