def get_geniusbar_page(store_number,
                       baseurl='http://concierge.apple.com/geniusbar/',
                       headers={}):
    page = webpage.WebPage(baseurl + store_number, None, headers=headers)
    data = page.get_data()
    Writefile('data/%s.html' % store_number, data.encode('utf-8'))
    return (data, page)
Пример #2
0
 def Get_workshops_url(self, storeUrl):
     page = GeniusbarPage(storeUrl)
     data = page.get_data()
     Writefile('debug/workshops.html', data)
     attrs = {'class': "nav hero-nav selfclear"}
     page_soup = page.get_soup()
     navtag = page_soup.find('nav', attrs=attrs)
     hrefs = navtag.findAll('a')
     url = None
     for href in hrefs:
         target = href.find('img', {'alt': 'Workshops'})
         if target:
             url = href.get('href')
             break
     return url
def test_login_page():
    baseUrl = "http://www.apple.com"
    storelist = "http://www.apple.com/cn/retail/storelist/"
    mainpage = webpage.WebPage(storelist)
    data = mainpage.get_data()
    headers = {}
    headers['Accept-Language'] = 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'
    headers[
        'User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
    headers[
        'Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
    headers["Connection"] = 'keep-alive'
    headers["Accept-Encoding"] = "gzip, deflate"
    #print(headers)

    #f = open('data/storelist.html', 'w')
    #f.write(data.encode('utf-8'))
    Writefile('data/storelist.html', data.encode('utf-8'))
    data = data.encode('utf-8')
    soup = mainpage.get_page(data)
    # find all store
    #<div id="cnstores" class="listing">
    attrs = {"id": "cnstores", "class": "listing"}
    tag = soup.find('div', attrs=attrs)
    hrefs = tag.findAll('a')
    suburl = None
    storeName = None
    for href in hrefs:
        suburl = href.get('href')
        storeName = href.getString().encode('utf-8', 'ignore')
        break

    storeurl = baseUrl + suburl
    debug.debug('%s: %s' % (storeName, storeurl))
    storepage = webpage.WebPage(storeurl)
    page_soup = storepage.get_page()
    Writefile('data/%s.html' % storeName.encode('gbk'), data)

    attrs = {'class': "nav hero-nav selfclear"}
    navtag = page_soup.find('nav', attrs=attrs)
    hrefs = navtag.findAll('a')
    support_url = None
    for href in hrefs:
        target = href.find('img', {'alt': 'Genius Bar'})
        if target:
            support_url = href.get('href')
            break
    post_data = {}
    support_page = webpage.WebPage(support_url)
    data = support_page.get_data()
    Writefile('data/support_page.html', data.encode('utf-8'))
    page_soup = support_page.get_page(data)
    # get form token
    attrs = {'type': 'hidden', "name": "_formToken"}
    tokentag = page_soup.find('input', attrs=attrs)
    post_data["_formToken"] = tokentag.get('value')
    # get selected store
    attrs = {'selected': 'selected'}

    store_tag = page_soup.find('option', attrs=attrs)
    post_data['storeNumber'] = store_tag.get('value')
    post_data['store'] = post_data['storeNumber']
    store_number = post_data['store']
    post_data['ruleType'] = 'TECHSUPPORT'
    headers['Referer'] = support_url
    headers['Host'] = 'concierge.apple.com'
    #headers['POST'] = '/reservation/ HTTP/1.1'
    url = "http://concierge.apple.com/reservation/"
    jump_page = webpage.WebPage(
        url, urllib.urlencode(post_data))  #, headers=headers)
    data = jump_page.get_data()
    Writefile('data/jump_page.html', data.encode('utf-8'))
    base_geniusbar = 'http://concierge.apple.com/geniusbar/'
    geniusbar_url = 'http://concierge.apple.com/geniusbar/' + post_data['store']
    headers = {}
    headers['Accept-Language'] = 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'
    headers[
        'User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
    headers[
        'Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
    headers["Connection"] = 'keep-alive'
    headers['Referer'] = support_url
    headers['Host'] = 'concierge.apple.com'
    geniusbar_page = webpage.WebPage(geniusbar_url, None, headers=headers)
    data = geniusbar_page.get_data()
    Writefile('data/getr401.html', data.encode('utf-8'))
    # post geniusbar store
    headers['Referer'] = geniusbar_url
    geniusbar_soup = geniusbar_page.get_page(data)
    attrs = {'type': 'hidden', "name": "_formToken"}
    tokentag = geniusbar_soup.find('input', attrs=attrs)
    post_data = {}
    post_data["_formToken"] = tokentag.get('value')
    post_data['supportOffered'] = 'true'
    geniusbar_detail_page = webpage.WebPage(geniusbar_url,
                                            urllib.urlencode(post_data),
                                            headers=headers)
    data = geniusbar_detail_page.get_data()
    Writefile('data/geniusbar_%s.html' % store_number, data)

    authenticate_url = 'https://idmsa.apple.com/IDMSWebAuth/authenticate'
    tag_names = [
        'Env', 'appIdKey', 'captchaType', 'captchaToken', 'grpCode',
        'language', 'iForgotNewWindowVar', 'paramcode', 'path', 'path2',
        'segment'
    ]

    post_data = build_post_data(geniusbar_detail_page.get_page(data),
                                tag_names)
    post_data['accountPassword'] = '******'
    post_data['appleId'] = '*****@*****.**'
    authenticate_page = webpage.WebPage(authenticate_url,
                                        data=urllib.urlencode(post_data),
                                        headers=headers)

    data = authenticate_page.get_data()
    Writefile('data/authenticate_page.html', data.encode('utf-8'))

    # post government id
    geniusbar_url = "https://concierge.apple.com/geniusbar/%s/governmentID" % store_number
    post_items = ['clientTimezone', 'FirstName', 'LastName']
    page_soup = authenticate_page.get_page(data)
    post_data = build_post_data(page_soup, post_items)
    if not post_data['clientTimezone']:
        post_data['clientTimezone'] = 'Asia/Shanghai'
    attrs = {'type': 'hidden', "name": "_formToken"}
    tokentag = page_soup.find('input', attrs=attrs)
    post_data["_formToken"] = tokentag.get('value')
    post_data['governmentID'] = '610102196103120670'
    post_data['governmentIDType'] = 'CN.PRCID'
    post_geniusbar_governmentid = webpage.WebPage(geniusbar_url,
                                                  urllib.urlencode(post_data),
                                                  headers)
    data = post_geniusbar_governmentid.get_data()
    page_soup = post_geniusbar_governmentid.get_page(data)
    Writefile('data/post_government_id.html', data.encode('utf-8'))
    data, geniusbar_page = get_geniusbar_page(store_number, headers=headers)
    page_soup = geniusbar_page.get_page(data)
    post_items = ['clientTimezone']
    post_data = build_post_data(page_soup, post_items)
    if not post_data['clientTimezone']:
        post_data['clientTimezone'] = 'Asia/Shanghai'
    attrs = {'type': 'hidden', "name": "_formToken"}
    tokentag = page_soup.find('input', attrs=attrs)
    post_data["_formToken"] = tokentag.get('value')
    attrs = {'class': 'NSCSSStateHidden value', "name": "id"}
    spantag = page_soup.find('span', attrs=attrs)
    post_data['id'] = spantag.text
    postbar = 'http://concierge.apple.com/geniusbar/R401'
    headers['Referer'] = postbar
    headers['Accept-Language'] = 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'
    reservicepage = webpage.WebPage(postbar,
                                    data=urllib.urlencode(post_data),
                                    headers=headers)
    data = reservicepage.get_data()
    Writefile('data/revers.html', data.encode('utf-8'))
    page_soup = reservicepage.get_page(data)
    attrs = {'id': 'captchaKey'}
    tag_key = page_soup.find("input", attrs=attrs)
    get_data = {}
    get_data['key'] = tag_key.get('value')
    attrs = {'id': "captchaFormat"}
    tag_format = page_soup.find("input", attrs=attrs)
    get_data['format'] = tag_format.get('value')
    import time
    get_data['t'] = str(time.time()).replace('.', '')
    url = "https://concierge.apple.com/geniusbar/R401/captcha?&%s" % urllib.urlencode(
        get_data)
    headers['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5'
    headers['Accept-Encoding'] = 'gzip, deflate'
    request = urllib2.Request(url, headers=headers)
    res = urllib2.urlopen(request)
    data = res.read()
    f = open('data/img.jpg', 'wb')
    f.write(data)
    f.close
Пример #4
0
    def waitingCmd(self, page, taskStatus):
        '''
        waiting the input
        '''
        runtime = 300  # waiting time
        storeUrl = taskStatus['storeUrl']
        debug.debug(storeUrl)

        while runtime > 0:
            taskCmd = taskStatus['taskCmd']
            if taskCmd == 'refresh':
                debug.debug('refresh cmd %s' % taskStatus['appleId'])
                verifycodedata, tSt = page.get_verification_code_pic()
                taskStatus['verifyCodeData'] = verifycodedata
                taskStatus['taskCmd'] = None
                time.sleep(1)
                continue
            if taskCmd == 'submit':
                debug.debug('get submit cmd %s' % taskStatus['appleId'])
                postData = page.build_submit_post_data()
                postData['captchaAnswer'] = taskStatus['captchaAnswer']
                postData['phoneNumber'] = taskStatus['phoneNumber']
                postData['smsCode'] = taskStatus['smsCode']
                postData['clientTimezone'] = taskStatus['clientTimezone']
                # 'Asia/Shanghai'
                submitUrl = self.challengeUrlFormat % GeniusbarPage.storeNumber
                headers = page.headers
                headers['Referer'] = submitUrl
                headers.pop('Accept-Encoding')
                submitpage = GeniusbarPage(submitUrl,
                                           data=urllib.urlencode(postData),
                                           headers=headers)
                data = submitpage.get_data()
                resultfile = 'tmp/%s.htm' % taskStatus['appleId']
                Writefile(resultfile, data)

                attrs = {
                    "class": "error-message on",
                    "id": "error_message_generalError"
                }
                errorMsg = submitpage.get_tag_text('label', attrs=attrs)
                if errorMsg:
                    taskStatus['cmdStatus'] = 'NOK'
                    taskStatus['taskCmd'] = None
                    taskStatus['prompInfo'] = errorMsg
                    page = submitpage
                    debug.error(errorMsg)
                    Writefile('tmp/submiterr.html', page.get_data())
                    continue
                else:
                    # success for submit
                    # get the time slots
                    ret, maxrow = self.buildTimeSlotsTable(submitpage)
                    taskStatus['cmdStatus'] = 'OK'
                    taskStatus['timeSlots'] = (ret, maxrow)
                    taskStatus['taskCmd'] = None
                    page = submitpage
                    continue
            if taskCmd == 'timeslot':
                # post timeslots
                debug.debug('get timeslot cmd %s' % taskStatus['appleId'])
                postData = self.buildPostTimeSlotsData(page)
                postData['clientTimezone'] = taskStatus['clientTimezone']
                postData['id'] = taskStatus['id']
                tlsUrl = self.timeslotFormat % GeniusbarPage.storeNumber
                debug.debug('tls ulr %s' % tlsUrl)
                headers = {}
                headers[
                    'Accept-Language'] = 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'
                headers[
                    'User-Agent'] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
                headers[
                    'Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
                headers["Connection"] = 'keep-alive'
                headers["Host"] = 'concierge.apple.com'
                tlspage = GeniusbarPage(tlsUrl,
                                        data=urllib.urlencode(postData),
                                        headers=headers)
                data = tlspage.get_data()
                Writefile('tmp/posttimeslotsresult.html', data)
                text = self.getConfirmMsg(tlspage)
                taskStatus['prompInfo'] = text.replace(' ', '')
                Writefile('tmp/reserv-%s' % taskStatus['appleId'],
                          taskStatus['prompInfo'])
                taskStatus['taskCmd'] = None
                taskStatus['cmdStatus'] = 'OK'
                break
            if taskCmd == 'end':
                taskStatus['taskCmd'] = None
                break
            #debug.debug('waiting cmd')
            time.sleep(1)
            runtime -= 1
        debug.info('End task %s' % taskStatus['appleId'])