ipcookie

import random,time,sys,os
from selenium import webdriver
from _weakref import proxy
import ssl
import json

sys.path += ["C:\\01mywork\\workspace\\TestAutomationForIT5\\TOMTOP\\Tools\\auto.test-0.0.1-jar-with-dependencies.jar"] 
#from com.tomtop.autotest import TomtopWebDriver

#def testJava():
    #TomtopWebDriver.openBrowser()
def getcurrentPath():
    return os.getcwd()

def firefox_proxy_options(ip,port):
    profile = webdriver.FirefoxProfile()
    profile.set_preference('network.proxy.type',1)
    profile.set_preference('network.proxy.http',ip)
    profile.set_preference('network.proxy.http_port',int(port))
    profile.set_preference('network.proxy.ssl',ip)
    profile.set_preference('network.proxy.ssl_port',int(port))
    profile.update_preferences()
    return profile
    
def getRandomNum(minNum,maxNum):
    if isinstance(minNum, int) and isinstance(maxNum, int):
        return random.randint(minNum,maxNum)
    if isinstance(minNum, long) or isinstance(maxNum, long):
        return random.randrange(minNum,maxNum)

def getCurTime():
    return time.strftime("%Y%m%d%H%M%S",time.localtime(time.time()))

def datalist_convert_str(*args):
    datastr ='('
    print args
    for listdata in args:
        for tupledata in listdata:
            print tupledata
            print tupledata[0]
            datastr += "'"+str(tupledata[0])+"'"
            datastr += ','
    datastr =datastr[:-1]   
    datastr += ')'
    return datastr

def datasetDecode(str):
    return str.decode('utf-8')

def tt_chrome_options():
    mobile_emulation = { "deviceName": "Apple iPhone 6 Plus"}
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
    return chrome_options

def ie_Options():
    options = webdriver.Ie()
    #options.add_argument('-user-data-dir=C:\Users\sunli\AppData\Local\Google\Chrome\User Data')
    options.add_argument('-user-data-dir=C:\Users\lenovo\AppData\Local\Google\Chrome\User Data')
    return options

def tomtop_Options():
    options = webdriver.ChromeOptions()
    #options.add_argument('-user-data-dir=C:\Users\sunli\AppData\Local\Google\Chrome\User Data')
    options.add_argument('-user-data-dir=C:\Users\lenovo\AppData\Local\Google\Chrome\User Data')
    return options

def proxy_Options(ip,Port):
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--proxy-server='+ip+':'+Port)
    #chrome_options.add_argument('--proxy-server=78.25.98.1114:8080')
    chrome_options.add_argument('--ignore-certificate-errors')
    return chrome_options

def proxy_capabilities_SSL():
    chrome_options = webdriver.ChromeOptions()
    #PROXY = "78.25.98.114:8080"
    #PROXY = "78.25.98.1114:8080"
    #chrome_options.add_argument('--proxy-server=78.25.98.1114:8080')
    capabilities = chrome_options.to_capabilities()
    #print capabilities
    # capabilities['proxy'] = {
    #"httpProxy":PROXY,
    #"proxyType":"MANUAL"
    #}
    capabilities['acceptSslCerts'] = True
    return capabilities

def get_Para(path):
    if os.path.exists(path):
        file = open(path)
        para = file.read().decode("utf-8")
        file.close()
    else:
        para = False
    return para

def output_Result(path,**kw):
    if os.path.exists(path):
        os.remove(path)
    file = open(path,'w')
    jsObj = json.dumps(kw)
    #print str
    #str = str.encode('utf-8')
    file.write(jsObj)
    file.close()
 
def to_str(**kw): 
    jsObj =  json.dumps(kw)
    return jsObj     
        
def convert_cookies(domain,cookie,*cookiename):
    #cookie='a-ogbcbff=1; skin=noskin; session-id-time=2082787201l; ubid-main=133-7356063-0747660; session-token="zJJReU6Ysa8sLt0oGox2Ur4MhR35SIKn6oPiy8/dz4+gU2KHujHr7NM6MVY1KjHM1usXlco7LIry9KmRREtHCFhIwQAkFvwIab3Roog2rZMzOSg05+TrancNRJp0BfncKUzl9tqduGCs111+niFUxnxhrhwm8CwYiGNFCOBd1ns9tcs+obe5DiZahsuekCIG1o2fke6YLid5S2CPwVEen0nkf+NP2eNfgWOteAYDEnOSG3WYjiAmOJpcP5MY+luLGCuzfUn4jgTNP+NNJiBCyA=="; session-id=143-7991598-9643717; ca=AK4AAAAAAAABAkQCQAAAAAA=; x-main=NFuTL96eo1hdVEsJT8H5i6C32JJvsIxchRBI5yBJSCaEiHdiYOm7tLiPBnkkrAE5; at-main=Atza|IwEBIGot6sShQaX6GAYBESVm5f3_-A3gSn5vja-IdaAq4Qc1EfN4wlOoepTe1KmqE7iL17gWaR5DaPNTnxiIGSZm6KosJNflIerhVxGEhagpdFcu6XM3A8RaNTlAEr1RT278W_TC7caopaGZyd-VjIdwtay-hXYJ6-iAsyAnTTw-YcGTXQNXtDvOQvk34CCInrWGEXNsPzVXzrMiR8nXhCqvkApDb9QNxO4-jG3SmxMVEhvoiLhOTMI7qWO_ZWHQrq7rcsJ1gkNAbEOiCSLmDRtrv4A5OuCaFIp53ZH_Xr_F5mQL7kZwc-OYzj5RVIVagpVrQDCMb2UirnsPtvR7OlhyRH_vrYUPUumK6ofSKc7xIVDOYDX-dmTYZX_c8LSaGMGnHd8-ERVj-hcJ8UwIymdmduaq; sess-at-main="iO7ARN2aXWMFIKF/4r50i+alHQTapmrpZaNGDRZhVSg="; sst-main=Sst1|PQGvsFxtacIIVtgegx1XPVcWCMHHiqZ9vvEsCq6pI3iZopr_TK4I110JEbFtEtDkCgCez14yCtUi7t026F8cd3rCjPh6S-mzHXiuWjmwioBa7pqfgeuutGYxyeda4BF_KuAmgEaVnquqNXFvE3jdni9_oKIfPN2djLEuHGSoZzJmmS6c0XXmy8Lke2HfzLVef0oYurOrUxNfVjdyYw9384AJkrVB5d1VeVvCd5FOSsL3VPYFa2vrJR6Z9JgB2c2B0NySau2ghh9GU2JEUEBVJZJCrg; lc-main=en_US; csm-hit=s-48Y21XX3NZDHZBY8Y9J6|1513324480534; x-wl-uid=1xNmr5jS4LPGEd118QSJ9CisX+4GNiiAnbIm6MNWfV2ZC9+a88Y4o2rE6slrh6hXJso6RNe8frB/TCz9xTDMekUEY/29iA+5y1+FCEK/WD4NA0At4VV4EjEK4jI1e5I+YzvmCUiLA0V4='
    cookiename = ['ap-fid','a-ogbcbff','session-id','session-id-time','a-ogbcbff','ubid-main','session-token','x-main','at-main','sess-at-main','lc-main']
    #domain =".amazon.com"
    standardCookies=[]
    list = cookie.split(';')
    for item in list:
        k,v = item.split('=',1)
        v=v.replace('"','')
        dict = {}
        if k.strip() in cookiename:
           dict["name"]= k.strip()
           dict["value"]=v 
           dict["domain"]=domain
           dict["path"]="/"
           dict["secure"]="false"
           dict["expirationDate"]=1609430399 #2020-12-31 23:59:59
           standardCookies.append(dict)
    standardCookies = json.dumps(standardCookies)
    return standardCookies 
   
def convert_cookiesForAmazonNotUS(domain,cookie):
    #cookie='a-ogbcbff=1; skin=noskin; session-id-time=2082787201l; ubid-main=133-7356063-0747660; session-token="zJJReU6Ysa8sLt0oGox2Ur4MhR35SIKn6oPiy8/dz4+gU2KHujHr7NM6MVY1KjHM1usXlco7LIry9KmRREtHCFhIwQAkFvwIab3Roog2rZMzOSg05+TrancNRJp0BfncKUzl9tqduGCs111+niFUxnxhrhwm8CwYiGNFCOBd1ns9tcs+obe5DiZahsuekCIG1o2fke6YLid5S2CPwVEen0nkf+NP2eNfgWOteAYDEnOSG3WYjiAmOJpcP5MY+luLGCuzfUn4jgTNP+NNJiBCyA=="; session-id=143-7991598-9643717; ca=AK4AAAAAAAABAkQCQAAAAAA=; x-main=NFuTL96eo1hdVEsJT8H5i6C32JJvsIxchRBI5yBJSCaEiHdiYOm7tLiPBnkkrAE5; at-main=Atza|IwEBIGot6sShQaX6GAYBESVm5f3_-A3gSn5vja-IdaAq4Qc1EfN4wlOoepTe1KmqE7iL17gWaR5DaPNTnxiIGSZm6KosJNflIerhVxGEhagpdFcu6XM3A8RaNTlAEr1RT278W_TC7caopaGZyd-VjIdwtay-hXYJ6-iAsyAnTTw-YcGTXQNXtDvOQvk34CCInrWGEXNsPzVXzrMiR8nXhCqvkApDb9QNxO4-jG3SmxMVEhvoiLhOTMI7qWO_ZWHQrq7rcsJ1gkNAbEOiCSLmDRtrv4A5OuCaFIp53ZH_Xr_F5mQL7kZwc-OYzj5RVIVagpVrQDCMb2UirnsPtvR7OlhyRH_vrYUPUumK6ofSKc7xIVDOYDX-dmTYZX_c8LSaGMGnHd8-ERVj-hcJ8UwIymdmduaq; sess-at-main="iO7ARN2aXWMFIKF/4r50i+alHQTapmrpZaNGDRZhVSg="; sst-main=Sst1|PQGvsFxtacIIVtgegx1XPVcWCMHHiqZ9vvEsCq6pI3iZopr_TK4I110JEbFtEtDkCgCez14yCtUi7t026F8cd3rCjPh6S-mzHXiuWjmwioBa7pqfgeuutGYxyeda4BF_KuAmgEaVnquqNXFvE3jdni9_oKIfPN2djLEuHGSoZzJmmS6c0XXmy8Lke2HfzLVef0oYurOrUxNfVjdyYw9384AJkrVB5d1VeVvCd5FOSsL3VPYFa2vrJR6Z9JgB2c2B0NySau2ghh9GU2JEUEBVJZJCrg; lc-main=en_US; csm-hit=s-48Y21XX3NZDHZBY8Y9J6|1513324480534; x-wl-uid=1xNmr5jS4LPGEd118QSJ9CisX+4GNiiAnbIm6MNWfV2ZC9+a88Y4o2rE6slrh6hXJso6RNe8frB/TCz9xTDMekUEY/29iA+5y1+FCEK/WD4NA0At4VV4EjEK4jI1e5I+YzvmCUiLA0V4='
    #domain =".amazon.com"
    standardCookies=[]
    list = cookie.split(';')
    for item in list:
        k,v = item.split('=',1)
        v=v.replace('"','')
        dict = {}
        dict["name"]= k.strip()
        dict["value"]=v 
        dict["domain"]=domain
        dict["path"]="/"
        dict["secure"]="false"
        dict["expirationDate"]=1609430399 #2020-12-31 23:59:59
        standardCookies.append(dict)
    standardCookies = json.dumps(standardCookies)
    return standardCookies    

def convert_cookies_ForWish(domain,cookie,*cookiename):
    #cookie='a-ogbcbff=1; skin=noskin; session-id-time=2082787201l; ubid-main=133-7356063-0747660; session-token="zJJReU6Ysa8sLt0oGox2Ur4MhR35SIKn6oPiy8/dz4+gU2KHujHr7NM6MVY1KjHM1usXlco7LIry9KmRREtHCFhIwQAkFvwIab3Roog2rZMzOSg05+TrancNRJp0BfncKUzl9tqduGCs111+niFUxnxhrhwm8CwYiGNFCOBd1ns9tcs+obe5DiZahsuekCIG1o2fke6YLid5S2CPwVEen0nkf+NP2eNfgWOteAYDEnOSG3WYjiAmOJpcP5MY+luLGCuzfUn4jgTNP+NNJiBCyA=="; session-id=143-7991598-9643717; ca=AK4AAAAAAAABAkQCQAAAAAA=; x-main=NFuTL96eo1hdVEsJT8H5i6C32JJvsIxchRBI5yBJSCaEiHdiYOm7tLiPBnkkrAE5; at-main=Atza|IwEBIGot6sShQaX6GAYBESVm5f3_-A3gSn5vja-IdaAq4Qc1EfN4wlOoepTe1KmqE7iL17gWaR5DaPNTnxiIGSZm6KosJNflIerhVxGEhagpdFcu6XM3A8RaNTlAEr1RT278W_TC7caopaGZyd-VjIdwtay-hXYJ6-iAsyAnTTw-YcGTXQNXtDvOQvk34CCInrWGEXNsPzVXzrMiR8nXhCqvkApDb9QNxO4-jG3SmxMVEhvoiLhOTMI7qWO_ZWHQrq7rcsJ1gkNAbEOiCSLmDRtrv4A5OuCaFIp53ZH_Xr_F5mQL7kZwc-OYzj5RVIVagpVrQDCMb2UirnsPtvR7OlhyRH_vrYUPUumK6ofSKc7xIVDOYDX-dmTYZX_c8LSaGMGnHd8-ERVj-hcJ8UwIymdmduaq; sess-at-main="iO7ARN2aXWMFIKF/4r50i+alHQTapmrpZaNGDRZhVSg="; sst-main=Sst1|PQGvsFxtacIIVtgegx1XPVcWCMHHiqZ9vvEsCq6pI3iZopr_TK4I110JEbFtEtDkCgCez14yCtUi7t026F8cd3rCjPh6S-mzHXiuWjmwioBa7pqfgeuutGYxyeda4BF_KuAmgEaVnquqNXFvE3jdni9_oKIfPN2djLEuHGSoZzJmmS6c0XXmy8Lke2HfzLVef0oYurOrUxNfVjdyYw9384AJkrVB5d1VeVvCd5FOSsL3VPYFa2vrJR6Z9JgB2c2B0NySau2ghh9GU2JEUEBVJZJCrg; lc-main=en_US; csm-hit=s-48Y21XX3NZDHZBY8Y9J6|1513324480534; x-wl-uid=1xNmr5jS4LPGEd118QSJ9CisX+4GNiiAnbIm6MNWfV2ZC9+a88Y4o2rE6slrh6hXJso6RNe8frB/TCz9xTDMekUEY/29iA+5y1+FCEK/WD4NA0At4VV4EjEK4jI1e5I+YzvmCUiLA0V4='
    cookiename = ['__utma','__utmb','__utmc','__utmt','__utmz','IR_PI','RT','bsid','sweeper_session','sweeper_uuid']
    #domain =".amazon.com"
    standardCookies=[]
    list = cookie.split(';')
    for item in list:
        k,v = item.split('=',1)
        v=v.replace('"','')
        dict = {}
        if k.strip() in cookiename:
           dict["name"]= k.strip()
           dict["value"]=v 
           dict["domain"]=domain
           dict["path"]="/"
           dict["secure"]="false"
           dict["expirationDate"]=1609430399 #2020-12-31 23:59:59
           standardCookies.append(dict)
    standardCookies = json.dumps(standardCookies)
    return standardCookies    

def input_cookies(filepath,ip,site,username,password,oldcookie,newcookie): 
    file = open(filepath,'a+')
    file.write(ip)
    file.write('\t')
    file.write(site)
    file.write('\t')
    file.write(username)
    file.write('\t')
    file.write(password)
    file.write('\t')
    file.write(oldcookie)
    file.write('\t')
    file.write(newcookie)
    file.write('\n')
    file.close()   


    
if __name__=="__main__":
    cookie='a-ogbcbff=1; skin=noskin; session-id-time=2082787201l; ubid-main=133-7356063-0747660; session-token="zJJReU6Ysa8sLt0oGox2Ur4MhR35SIKn6oPiy8/dz4+gU2KHujHr7NM6MVY1KjHM1usXlco7LIry9KmRREtHCFhIwQAkFvwIab3Roog2rZMzOSg05+TrancNRJp0BfncKUzl9tqduGCs111+niFUxnxhrhwm8CwYiGNFCOBd1ns9tcs+obe5DiZahsuekCIG1o2fke6YLid5S2CPwVEen0nkf+NP2eNfgWOteAYDEnOSG3WYjiAmOJpcP5MY+luLGCuzfUn4jgTNP+NNJiBCyA=="; session-id=143-7991598-9643717; ca=AK4AAAAAAAABAkQCQAAAAAA=; x-main=NFuTL96eo1hdVEsJT8H5i6C32JJvsIxchRBI5yBJSCaEiHdiYOm7tLiPBnkkrAE5; at-main=Atza|IwEBIGot6sShQaX6GAYBESVm5f3_-A3gSn5vja-IdaAq4Qc1EfN4wlOoepTe1KmqE7iL17gWaR5DaPNTnxiIGSZm6KosJNflIerhVxGEhagpdFcu6XM3A8RaNTlAEr1RT278W_TC7caopaGZyd-VjIdwtay-hXYJ6-iAsyAnTTw-YcGTXQNXtDvOQvk34CCInrWGEXNsPzVXzrMiR8nXhCqvkApDb9QNxO4-jG3SmxMVEhvoiLhOTMI7qWO_ZWHQrq7rcsJ1gkNAbEOiCSLmDRtrv4A5OuCaFIp53ZH_Xr_F5mQL7kZwc-OYzj5RVIVagpVrQDCMb2UirnsPtvR7OlhyRH_vrYUPUumK6ofSKc7xIVDOYDX-dmTYZX_c8LSaGMGnHd8-ERVj-hcJ8UwIymdmduaq; sess-at-main="iO7ARN2aXWMFIKF/4r50i+alHQTapmrpZaNGDRZhVSg="; sst-main=Sst1|PQGvsFxtacIIVtgegx1XPVcWCMHHiqZ9vvEsCq6pI3iZopr_TK4I110JEbFtEtDkCgCez14yCtUi7t026F8cd3rCjPh6S-mzHXiuWjmwioBa7pqfgeuutGYxyeda4BF_KuAmgEaVnquqNXFvE3jdni9_oKIfPN2djLEuHGSoZzJmmS6c0XXmy8Lke2HfzLVef0oYurOrUxNfVjdyYw9384AJkrVB5d1VeVvCd5FOSsL3VPYFa2vrJR6Z9JgB2c2B0NySau2ghh9GU2JEUEBVJZJCrg; lc-main=en_US; csm-hit=s-48Y21XX3NZDHZBY8Y9J6|1513324480534; x-wl-uid=1xNmr5jS4LPGEd118QSJ9CisX+4GNiiAnbIm6MNWfV2ZC9+a88Y4o2rE6slrh6hXJso6RNe8frB/TCz9xTDMekUEY/29iA+5y1+FCEK/WD4NA0At4VV4EjEK4jI1e5I+YzvmCUiLA0V4='
    cookiename = ['ap-fid','a-ogbcbff','session-id','session-id-time','a-ogbcbff','ubid-main','session-token','x-main','at-main','sess-at-main','lc-main']
    file = open('C:\\01mywork\\workspace\\ROBOT\\TestAutomationForIT5\cookie.txt','a+')
    file.write('test@qq.com')
    file.write('\t')
    file.write(cookie)
    file.write('\t')
    standardCookies = convert_cookies('.amazon.com',cookie,*cookiename)
    file.write(standardCookies)
    file.write('\n')    
    file.write('lll@qq.com')
    file.write('\t')
    file.write(cookie)
    file.write('\t')
    standardCookies = convert_cookies('.amazon.com',cookie,*cookiename)
    file.write(standardCookies)
    file.write('\n')
    file.close()
    
        
    

 

posted @ 2018-06-16 17:28  天际流云  阅读(557)  评论(0编辑  收藏  举报