
from pprint import pprint
import logging
logging.captureWarnings(True)
import requests
import re
import requests
import json
import os
from pprint import pprint
os.environ['NO_PROXY'] = 'stackoverflow.com'
from curl_cffi import requests
from scrapy.selector import Selector
from datetime import datetime
from all_connect import ConnectSpider
Con = ConnectSpider()
import time
import random
class GetCookie(object):
    def __init__(self):
        pass

    def get_cookie(self,username,password,test_id):
        # url = "https://accounts.shutterstock.com/oauth/authorize"
        # response = requests.get(url, headers=headers, allow_redirects=False)
        # # print(response)
        # cookies = dict(response.cookies)
        # # pprint(cookies)

        headers = {
            'accept': 'application/json',
            'accept-language': 'zh-CN,zh;q=0.9',
            'content-type': 'application/json',
            # 'cookie': 'stck_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; sstk_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; _gcl_au=1.1.612940543.1725355186; __ssid=ba410212754b3a62d2687a791f52c1a; _ga=GA1.1.200858045.1725355186; did=9852f99c-ae8d-41a7-9263-cb68b8d6164d; accts_customer=chenxiaowei70; accts_customer_sso1=401642949-undefined; next.sid=s%3ARXkBpmFV18H84ZTlhxC5HA1MCXcGbWEz.x4av90eE2p0gIegIgxmNo9%2BholArtlFKZTXEdm3OQvc; _4c_=%7B%22_4c_mc_%22%3A%22ff9520d4-fc5e-4b9c-892e-2c0bf39ef51a%22%7D; FPID=FPID2.2.5SpZVlHvrtXYz0M8C0t7GGlMlT9hUzgKcD4FRT%2F0rAM%3D.1725355186; visitor_id=73568925800; htjs_user_id=401642949; htjs_anonymous_id=7c4b5046-d8eb-4ee5-8bac-893a170fa766; sliguid=5f80ac9c-7468-44a5-a464-cb1ceb0439c7; slirequested=true; extole_access_token=Q1U7HGT00HC3CMFJQ2PAD0KUDQ; _ga_5JRYE4Y8J9=GS1.1.1726103781.4.0.1726103781.60.0.0; _ga_H22ZZQTXLV=GS1.1.1726103781.4.0.1726103781.0.0.0; locale=zh; NEXT_LOCALE=zh; hl=zh; downlink=slow; n_v=RCV2DuhCEsefvAEwPNczi; sstk_session_start=2024-09-14T01%3A19%3A23.838Z; stck_session_id=60b0982a-606d-4ca2-a683-d4631097d614; sstk_session_id=60b0982a-606d-4ca2-a683-d4631097d614; visit_id=81448935507; fullstory_enabled=false; OptanonCachedGroups=,C0001,C0003,C0002,C0005,C0004,; FPLC=MhJwfs4em%2FvHDCW22rk0s6n1fC%2BjDF32oKEW8ev5%2BwH3z%2FbGwyI39m5EenAU5F24ndYkdWHJfoKB2YvNe7T30dlv1wxAZeuDJc%2FvYwCXt%2FSDS5%2B7wApbhWzat%2FmWdQ%3D%3D; slireg=https://scout.us1.salesloft.com; datadome=T68kQIp1WWnyUdSsbqVYAp__d5Tvbp8XDguDFBeK2BNzhMv0sffU_Vdnu0SaNYa0M4bW7gHlYK~7t6ehtmmC46QV5Ocv0aJ6YO3MK39J~UF4giZ4l84Xkgd74SCJeW7e; _ga_SSGTMSSTK=GS1.1.1726276775.3.1.1726276929.0.0.2058912936; Authorization=1%2FeyJjbGllbnRfaWQiOiJhMGI3Ni1hN2Y1ZS1mZWRlYy1iYmViZS1mYTY1Yi04NTcxOSIsInJlYWxtIjoiY3VzdG9tZXIiLCJzY29wZSI6InVzZXIudmlldyB1c2VyLmVtYWlsIHVzZXIuYWRkcmVzcyB1c2VyLmVkaXQgb3JnYW5pemF0aW9uLnZpZXcgb3JnYW5pemF0aW9uLmFkZHJlc3MgY29sbGVjdGlvbnMudmlldyBjb2xsZWN0aW9ucy5lZGl0IGxpY2Vuc2VzLnZpZXcgbGljZW5zZXMuY3JlYXRlIG1lZGlhLnVwbG9hZCBtZWRpYS5zdWJtaXQgbWVkaWEuZWRpdCBwdXJjaGFzZXMudmlldyBwdXJjaGFzZXMuY3JlYXRlIiwidXR2IjoidE9VSyIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ1c2VybmFtZSI6ImNoZW54aWFvd2VpNzAiLCJ1c2VyX2lkIjo0MDE2NDI5NDksIm9yZ2FuaXphdGlvbl9pZCI6bnVsbCwicGFyZW50X29yZ2FuaXphdGlvbl9pZHMiOltdLCJjdXN0b21lcl9pZCI6NDAxNjQyOTQ5LCJleHAiOjE3MjYyODAzMzV9.Jm_9UkRn9HFFPt3N9SkgfswEE6zKcKCLLtANgYEV-oizIbLwVceEpQt6OhS40OCHWy8BtnYVqD0FywVO0D7MYg; _uetsid=69272480723711ef81e4916cada775b8|6fkmu5|2|fp6|0|1718; _uetvid=58dc29704a6511ef8f5e5754465f397d|1unxtqr|1726276930405|2|1|bat.bing.com/p/insights/c/z; OptanonAlertBoxClosed=2024-09-14T01:26:47.115Z; OptanonConsent=consentId=0f52ec73-6a09-4521-a9f6-656d9345d77a&datestamp=Sat+Sep+14+2024+09%3A26%3A47+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=202403.2.0&interactionCount=2&isAnonUser=1&isGpcEnabled=0&browserGpcFlag=0&isIABGlobal=false&hosts=&landingPath=NotLandingPage&groups=C0001%3A1%2CC0003%3A1%2CC0002%3A1%2CC0005%3A1%2CC0004%3A1&AwaitingReconsent=false&intType=3; _ga_VEW1GCS46P=GS1.1.1726276775.1.1.1726277225.37.0.0',
            'newrelic': 'eyJ2IjpbMCwxXSwiZCI6eyJ0eSI6IkJyb3dzZXIiLCJhYyI6Ijk2NzIzMiIsImFwIjoiMTU4ODYzMjc5MiIsImlkIjoiOGM2ZmE0ZjI1NjBjMzNkYyIsInRyIjoiOWE1MTY5ODE0MDdjYzU4ODkxNDEwMzBhYTY0YjljYWQiLCJ0aSI6MTcyNjI3NzIzMjc2M319',
            'origin': 'https://www.shutterstock.com',
            'priority': 'u=1, i',
            'referer': 'https://www.shutterstock.com/zh/catalog/licenses?q=2115440474',
            'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'traceparent': '00-9a516981407cc5889141030aa64b9cad-8c6fa4f2560c33dc-01',
            'tracestate': '967232@nr=0-1-967232-1588632792-8c6fa4f2560c33dc----1726277232763',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
            'x-end-app-name': 'next-web',
            'x-end-app-version': 'RCV2DuhCEsefvAEwPNczi',
            'x-newrelic-id': 'XQAAU1VRGwIEVVhaBgYGUlI=',
            'x-request-id': '796bfe4c-8f04-46d7-8d08-3fd822e90caf',
        }
        cookies = {"session": "s%3AI9ziS788AduDlnYyY0e6UZdoGVzIsSP5.exVKScJJaVstpM2QMk0XT1fceF9QproiKiBCL6HNY9I",}
        url = "https://accounts.shutterstock.com/login"
        data = {
            "username": f"{username}",
            "password":  f"{password}",
            "next": "/oauth/authorize?state=3bd2f73742d0b1cb84c3c015d034e291&redirect_uri=https%3A%2F%2Fwww.shutterstock.com%2Fnext-oauth%2Fcallback%3Flanding_page%3D%252Fiframe-landing%253Fpreset%253Dcvrt839%26realm%3Dcustomer&scope=licenses.create%20licenses.view%20organization.view%20purchases.view%20purchases.create%20user.edit%20user.email%20user.view%20user.address%20organization.address%20collections.view%20collections.edit%20media.upload%20media.submit%20media.edit&site=image&embedded=true&preset=cvrt839&client_id=a0b76-a7f5e-fedec-bbebe-fa65b-85719",
            "g-recaptcha-response": "03AFcWeA7Y3BMoHRIe-_m4-BWBpyWg2kmp8pydIOMsAk4Fd7djxmnMq4D2sSsJsbAg5rnpwYhvVw0i0x_n5_pitX76Ju0EdRD9dBwpbyUN1CvMGyS_hY9yA0QdSSElvgh9GAAXvy1sIIFymSDMpoQIG0CAB_ybvRAlnJwfb6oifrb2Yi3UBW9HkMe2cPvZBdD4ApitfP7UVk3BOk7ct2UFbPx9uvtSUeliCTFr8C4l-VrjOBR11j1rRSHvD9vLJPrne7O2I1Bp3Fu1mLCpefaVq1t1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WRog9r3I86ncLAzUfPCD3ww1mlQMRB6Lzj2yhu8MFyQpjlb_H-wrp9scdswH6ajV-kna7W4lmoTa12iH_nBuAncLy7I0RxxQgrUadjswJ9s4TOQF9chmX6Pat8WR79gZiGeQ-yBaGCrMM0iHs0ALZveRPmiaaKuD2kv8V7y9TmT_Ex3DIS6IeiLnXOBZ2hJBEWnEuYzg3GxXVNsDzdNEmejK8TB7Jb783rh9y2WEOp00fqdvtRl-yFJX9Q6HtejWge3ttoasR2rF4m1J0wSl8jNcd0PEyvp4IeHQrknF_cB5CWDxZkM6RJNQhQ8OiC5UDmJ3lVGMP-rcukp_ap4ZDVUxRQbtLN9pYPYnWMEPMTAEp_yMoobguxLWWbV37sIq610SSE7IXeR8eDa9iYTfDCAMNA-RK0nOVEg-yd3_A1VGBjVgApj7Z8GL09XRuvk0Av8vuz7G9B3GFyUxk6CZb-JdreekV3G_DAMhHolgxQkwECvSvIJL51pD4SBCp5IUWi3GmLHCbjFx74_Q1xs9cYchOu6V01kziNoyx2Vf4ThHJpaBY1-5K1H_MiA28IlkJPax8NwTYaY0eHs61hcqGZRx9ioG1lBKs3MprHiykvwleWj_ff4v_v7JrNVKdCSt4GMKnOcAtx19e413rtzBi50bwmFRU9btX3KGFMWw1JQ7y6skbwm8XqtslyAKm_KpbyVdTTqRwt-rBdyMmhpaKe1EzeFDwCOTrUVUEbiuCrOTa512PILKXKtx2g9Rk3k7Vea-QYg2bqtLCsQ"
        }


        # data = {
        #     "username": "danqingmei30",
        #     "password": "yswg2468.",
        #     "next": "/oauth/authorize?state=655089be46ef190d6e41a83c1f6514ef&redirect_uri=https%3A%2F%2Fwww.shutterstock.com%2Fnext-oauth%2Fcallback%3Flanding_page%3D%252Fiframe-landing%253Fpreset%253Dcvrt839%26realm%3Dcustomer&scope=licenses.create%20licenses.view%20organization.view%20purchases.view%20purchases.create%20user.edit%20user.email%20user.view%20user.address%20organization.address%20collections.view%20collections.edit%20media.upload%20media.submit%20media.edit&site=image&embedded=true&preset=cvrt839&client_id=a0b76-a7f5e-fedec-bbebe-fa65b-85719",
        #     "g-recaptcha-response": ""
        # }
        # data = {
        #     "username": "771783160@qq.com",
        #     "password": "XUEYi15999866920!",
        #     "next": "/oauth/authorize?state=28d2a63c10744eb7b3d9cd97a6fd295f&redirect_uri=https%3A%2F%2Fwww.shutterstock.com%2Fnext-oauth%2Fcallback%3Flanding_page%3D%252Fiframe-landing%253Fpreset%253Dcvrt839%26realm%3Dcustomer&scope=licenses.create%20licenses.view%20organization.view%20purchases.view%20purchases.create%20user.edit%20user.email%20user.view%20user.address%20organization.address%20collections.view%20collections.edit%20media.upload%20media.submit%20media.edit&site=image&embedded=true&preset=cvrt839&client_id=a0b76-a7f5e-fedec-bbebe-fa65b-85719",
        #     # "g-recaptcha-response": "03AFcWeA6Ql-DumMbMjl0JWU1I9Xv-p1YQ5R1gGs9lFRCpym1ofD6E0esdR3HPH6JL-ZkhgmtyFs8Ez502BVBaVSbwjp3unfcMzXC3GwTkbt4nU9BSCihmrvllR7-XtpWiOV8WnM4MtxU5tHmTBqFg-lWmWikR2uRbuikt4NMJ6YLd3b-Q39IIf1wqyhUC3USGuAUMOZCEJMnIbMDv0p0g2MM0hiuF4KYVliks1WoeXyFKGEsRXB3ZDfImf1YTXQQFuEMZ4D7NIESvnlzuRXQRcXWE2DIC6WieuWDT_mEQBDcPTQP9z9un_7Xhwtku1CegdqRzPekG839z89ei_6uj881i5eeWcfkuysUa-6H-HJm37-jW6_-lTymFf5X_tFpAo-IEoeS7IaXKBmYiDG5xhjGpZQY--kKNS6Ygj9p_HfKzS5Lz6Nah6D4OXDmZXtkZcpVKNhPwIQ3m_FaYNCKxNRAbsTF3suPGNVxl61qg-1cG-09PGJ5o2uSx9Spa4CtNRC-jhmyjfXTCp5vv3AuRSKgONstBbZyAq6FJhrxUIMjTZ9rWUXnOVhUAaJKwb8ARlqXgEZOWyin7PhQcs6TyHBACifU7Nx5hoL-ujFD9BdynbdIcD1bOZWJ0zbg0cT-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YsD8CMt8xMjbDLu4AEww2RfJ-sll6pN10KLZAZYgEfu7ZcFoZBn9J8zLdgQRrUBTLIj14rB4ZtRVKG9Yu26zER49OV-UI043XU8qkr13u_Vvhe1SA4e0dhUxvMxHtpTxISzcfx1HcBW4BrN1JU-qnJWKBBGpDu9JoDsYC5s8wDHDTbMOXKRbQBzzMiTgAUJmpZWCkvcV8Rhtb_b0Pf7vsCtel-Iqm6lZbB9Owiw71BWzqFaBLH_z_FYCn2KNnAfPIhMsW1rRW1NinMSgT-sFtmDX3CHQ5yCOY61L_18DsfY_AOClx3mu23m4aKt19Mq8TcXkTi-EDWjLuYBi_ofGJpCq4Sy_BzGJ4VEbqf7zzl713yDbajntTwZqV6tcc-TEWLUS5ImxNwhrrUKqQpR-i2xf9IBr6J4N9dEa_UsIqCuLN6P7Hva0qtw"
        # }
        # data = {
        #     "username": "yuanminghui@yswg.com.cn",
        #     "password": "yswg2024",
        #     "next": "/oauth/authorize?state=b6ab9ef1819945a0b22b1dc0875be823&redirect_uri=https%3A%2F%2Fwww.shutterstock.com%2Fnext-oauth%2Fcallback%3Flanding_page%3D%252Fiframe-landing%253Fpreset%253Dcvrt839%26realm%3Dcustomer&scope=licenses.create%20licenses.view%20organization.view%20purchases.view%20purchases.create%20user.edit%20user.email%20user.view%20user.address%20organization.address%20collections.view%20collections.edit%20media.upload%20media.submit%20media.edit&site=image&embedded=true&preset=cvrt839&client_id=a0b76-a7f5e-fedec-bbebe-fa65b-85719",
        #     "g-recaptcha-response": ""
        # }
        # data = {
        #     "username": "496775268@qq.com",
        #     "password": "Chen2436326542",
        #     "next": "/oauth/authorize?state=8da6aa890810d3c91856e371873cfe11&redirect_uri=https%3A%2F%2Fwww.shutterstock.com%2Fnext-oauth%2Fcallback%3Flanding_page%3D%252Fiframe-landing%253Fpreset%253Dcvrt839%26realm%3Dcustomer&scope=licenses.create%20licenses.view%20organization.view%20purchases.view%20purchases.create%20user.edit%20user.email%20user.view%20user.address%20organization.address%20collections.view%20collections.edit%20media.upload%20media.submit%20media.edit&site=image&embedded=true&preset=cvrt839&client_id=a0b76-a7f5e-fedec-bbebe-fa65b-85719",
        #     "g-recaptcha-response": "03AFcWeA4n5lvMh7UbNUvMRRYzU63dN_1ApJHWNeQeUPMuLWCDVkWHHMha4GlA9Dj4ZG1mAwNAEcn_AeuOLmZV3AF0MYf0OcJlmDyVhGaLaAmsm7IunwyqMOX9hkFG68CT4ErCbjWm5iJ7r2S5BErp0jSHUdmtz9Nzsr6RMEnct0JBeh3jYWqrYNIYWrlKRTs1e80I_gjA5RqURA22Q5f5WXFVr374XhZrJMclI7bpMUBFjSzYJbVuMNCMlRZ-zY-aqgjUFf0A3p3cyTqlob2juP1UrrGnaPvHyj5UJA3uEWfX6MySYJs2MSSOyz8AtOdnhKBEINIQDOSoBIhKi-ErrKpY-EdWEnjkjbW6tcw87u8ol5BEbV1CCBh-oRXOCbuzr8_QSFC0uhrUKdf1lqJfq1wkYLca6O4SYMH0IFT7AiImMaXXqvu18efQ8clJZV7mjyyue8DMHWqsBpjOr2qG8_vjYTReU2FY0D3BzLMbZcuEw3-SgQiIxaLUIe0atkZkLkgwwz6ZxHUzzaSl8MI_vTxhi0VxVk26oB-6KLnED5LvvgX5SFyYkw-spwrDa977MhiQbDJRjxfGRrnl6dLDwk8Rw4fovHEWxHobaqIE_oEmFPQDBDJXgCQ8UCec1lgwsAZAFU26VJdgUheSbKpTkN4Ch33uWCVFlbg9blLusOZjV6KTrbj72Ob_F7yQu5Z05IExUYvwKkPOqv1ypFNeRkV6Mz_iN8C6HGkNSLsQAJlWAQbuV4yDU6y7TfJVG1PR5pkSWtBDn4kQ9TXZCgahfCFLPmbIcIr3eNQ0hft_Kx93N4GFsopoYnW0xmva4LzFyuAo0EMcZrdu_lOgEiiScCyW4CnoybVs3Ywwrm0pkzsb49uXYXudjnIRAE6TdmhRoAi6PXZiCYZMMvctsf6XUSoJD4VhNkuq2ihNENBnNf3s-BPktn9kOtdPVw46mhcWgcvGSjj5_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mMujhY68ZznvoVvrJkCVtdTMZau31i0YNsig6WNny9dA"
        # }
        time.sleep(random.randint(1,3))
        data = json.dumps(data, separators=(',', ':'))
        response = requests.post(url, headers=headers, cookies=cookies, data=data,verify=False, allow_redirects=False)
        print(111111111111)
        print(response.status_code)
        print(response.text)
        print("\n")
        cookies1 = dict(response.cookies)
        # pprint(cookies1)
        url = response.json()['next_url']
        time.sleep(random.randint(1, 3))



        headers = {
            "Host": "www.shutterstock.com",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "referer": "https://accounts.shutterstock.com/",
            "accept-language": "zh-CN,zh;q=0.9",
        }
        response = requests.get(url, headers=headers, cookies=cookies1,verify=False,  allow_redirects=False)
        print(2222222222222)
        print(url)
        print(response.status_code)
        print(response.text)
        print("\n")
        # <p>Found. Redirecting to <a href="/iframe-landing?preset=cvrt839">/iframe-landing?preset=cvrt839</a></p
        cookies2 = dict(response.cookies)
        cookies3 = {**cookies1, **cookies2}
        time.sleep(random.randint(1, 3))

        headers = {
            "Host": "www.shutterstock.com",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "referer": "https://accounts.shutterstock.com/",
            "accept-language": "zh-CN,zh;q=0.9",
        }
        url = "https://www.shutterstock.com/iframe-landing"
        params = {
            "preset": "cvrt839"
        }
        response = requests.get(url, headers=headers, cookies=cookies3, params=params,verify=False, allow_redirects=False)
        # print(3333333333)
        # print(url)
        # print(response.status_code)
        # print(response.text)
        # print("\n")
        cookies4 = dict(response.cookies)
        cookies5 = {**cookies3, **cookies4}

        time.sleep(random.randint(1, 3))
        sel = Selector(text=response.text, type="html")
        url = sel.xpath(".//a/@href").get()
        headers = {
            "Host": "accounts.shutterstock.com",
            "upgrade-insecure-requests": "1",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "referer": "https://accounts.shutterstock.com/",
            "accept-language": "zh-CN,zh;q=0.9",
        }
        response = requests.get(url, headers=headers, cookies=cookies5,verify=False, allow_redirects=False)
        # print(444444444)
        # print(url)
        # print(response.status_code)
        # print(response.text)
        # print("\n")
        cookies6 = dict(response.cookies)
        # pprint(cookies6)
        cookies7 = {**cookies5, **cookies6}

        time.sleep(random.randint(1, 3))
        sel = Selector(text=response.text, type="html")
        url = sel.xpath(".//a/@href").get()
        headers = {
            "Host": "www.shutterstock.com",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "referer": "https://accounts.shutterstock.com/",
            "accept-language": "zh-CN,zh;q=0.9",
        }
        response = requests.get(url, headers=headers, cookies=cookies7,verify=False, allow_redirects=False)
        # print(55555555)
        # print(url)
        # print(response.status_code)
        # print(response.text)
        # print("\n")
        cookies8 = dict(response.cookies)
        cookies9 = {**cookies7, **cookies8}
        # pprint(cookies9)

        time.sleep(random.randint(1, 3))
        headers = {
            "Host": "www.shutterstock.com",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "referer": "https://accounts.shutterstock.com/",
            "accept-language": "zh-CN,zh;q=0.9",
            "priority": "u=0, i"
        }
        url = "https://www.shutterstock.com/iframe-landing"
        params = {
            "preset": "cvrt839"
        }
        response = requests.get(url, headers=headers, cookies=cookies,verify=False, allow_redirects=False)
        # print(666666666)
        # print(url)
        # print(response.status_code)
        # print(response.text)
        # print("\n")
        cookies10 = dict(response.cookies)
        cookies11 = {**cookies9, **cookies10}
        # pprint(cookies11)

        time.sleep(random.randint(1, 3))
        headers = {
            "Host": "www.shutterstock.com",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "referer": "https://accounts.shutterstock.com/",
            # "priority": "u=0, i"
        }
        cookies = {}
        url = "https://www.shutterstock.com/zh/iframe-landing"
        params = {
            "preset": "cvrt839"
        }
        response = requests.get(url, headers=headers, cookies=cookies, params=params,verify=False, allow_redirects=False)
        # print(77777777)
        # print(url)
        # print(response.status_code)
        # print(response.text)
        # print("\n")
        cookies12 = dict(response.cookies)
        cookies13 = {**cookies11, **cookies12}
        # pprint(cookies13)

        time.sleep(random.randint(1, 3))
        headers = {
            'accept': 'application/json',
            'accept-language': 'zh-CN,zh;q=0.9',
            'content-type': 'application/json',
            'newrelic': 'eyJ2IjpbMCwxXSwiZCI6eyJ0eSI6IkJyb3dzZXIiLCJhYyI6Ijk2NzIzMiIsImFwIjoiMTU4ODYzMjc5MiIsImlkIjoiNDFhZjVlNmU1Zjc3MTcyOCIsInRyIjoiMWY1OTI1N2E0ODM4Y2Q5ZmRiYTZkZTQ0YmI0NjVjNmUiLCJ0aSI6MTcyMzUxMTc2NDcwOX19',
            'origin': 'https://www.shutterstock.com',
            'priority': 'u=1, i',
            'referer': 'https://www.shutterstock.com/zh/catalog/licenses',
            'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'traceparent': '00-1f59257a4838cd9fdba6de44bb465c6e-41af5e6e5f771728-01',
            'tracestate': '967232@nr=0-1-967232-1588632792-41af5e6e5f771728----1723511764709',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
            'x-end-app-name': 'next-web',
            'x-end-app-version': '52ce3cb0535',
            'x-newrelic-id': 'XQAAU1VRGwIEVVhaBgYGUlI=',
            'x-request-id': '3712d198-d49f-43e6-b813-0ad30b2034bc',
        }
        params = {
            'v': '52ce3cb0535',
        }
        json_data = {
            'required_cookies': '',
            'content': [
                {
                    'content_id': f'{test_id}',
                    'content_type': 'photo',
                    'content_size': 'huge',
                    'content_format': 'jpg',
                    'license_name': 'standard',
                    'show_modal': True,
                },
            ],
        }
        response = requests.post('https://www.shutterstock.com/napi/licensees/current/redownload',params=params,cookies=cookies13,headers=headers,json=json_data,verify=False, allow_redirects=False)

        # print('测试')
        # print(response.status_code)
        # print(response.text)
        return response,cookies13

    def save_cookies(self,username,cookie13):
        item = {}
        item['account_id'] = username
        item['cookie'] = json.dumps(cookie13)
        item['state'] = 1
        item['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        Con.save_stock_cookie(item)

    #
    def run(self):
        # for item_id in range(4,30):
            item_id = 1
            account_list = Con.get_cookie_account(item_id)
            username = account_list[0]
            password = account_list[1]
            test_id = Con.get_stock_test_id(username)
            # print(username,password)
            # test_id = '458951890'
            print(item_id,username,password,test_id)

            count = 0
            while count < 20:
                response,cookie13 = self.get_cookie(username,password,test_id)
                if response.status_code == 200:
                    self.save_cookies(username,cookie13)
                    print(f'{username},保存第{count+1}个')
                    time.sleep(random.randint(3,6))
                    count += 1
                else:
                    print(response.status_code)
                    print(response.text)

if __name__ == '__main__':
    get_cookie = GetCookie()
    get_cookie.run()




