Skip to content

Instantly share code, notes, and snippets.

@nikop
Last active December 17, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikop/5592734 to your computer and use it in GitHub Desktop.
Save nikop/5592734 to your computer and use it in GitHub Desktop.
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