Skip to content

Instantly share code, notes, and snippets.

@drx drx/
Created Jun 12, 2012

What would you like to do?
Tiny script to scrape Apple Online Store every second and check for changes in MacBook availability
import urllib2
import re
import time
import pycurl
import StringIO
#url = ""
url = ""
prev_delivery = (None, None)
while True:
#f = urllib2.urlopen(url)
#html =
b = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.PROXY, 'localhost')
c.setopt(pycurl.PROXYPORT, 40000)
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
c.setopt(pycurl.WRITEFUNCTION, b.write)
html = b.getvalue()
delivery = re.findall('<li class="description">\s*[^/]*?<sup>1</sup>\s*</li>.*?<span class="customer_commit_display">(.*?)</span>', html, re.S)
for i in range(len(delivery)):
if delivery[i] != prev_delivery[i]:
print 'Change: ', delivery
for j in range(5):
prev_delivery = delivery
print time.strftime("%H:%M:%S")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.