0

Im kindly trying to register on a registration page but my goal is each time I do the loop I want a new chrome profile and cookies and proxy like a new device connected Im using rotational proxy and im sure my problem is not the proxy here

class NewIdentity(object):
    def __init__(self):
        self.curhostname = "xx.xxx.xxx"
        self.curport = "xxxx"
        self.proxy_username = 'xxxxxx' # username
        self.proxy_password = 'xxxxxx'# password
        
        
        self.manifest_json = """
        {
        "version": "1.0.0",
        "manifest_version": 2,
        "name": "Chrome Proxy",
        "permissions": [
            "proxy",
            "tabs",
            "unlimitedStorage",
            "storage",
            "<all_urls>",
            "webRequest",
            "webRequestBlocking"
        ],
        "background": {
            "scripts": ["background.js"]
        },
        "minimum_chrome_version":"22.0.0"
        }
        """

        self.background_js = """
        var config = {
            mode: "fixed_servers",
            rules: {
            singleProxy: {
                scheme: "http",
                host: "%s",
                port: parseInt(%s)
            },
            bypassList: ["localhost"]
            }
        };

        chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

        function callbackFn(details) {
            return {
                authCredentials: {
                username: "%s",
                password: "%s"
                }
            };
        }

        chrome.webRequest.onAuthRequired.addListener(
                callbackFn,
                {urls: ["<all_urls>"]},
                ['blocking']
        );
        """ % (self.curhostname, self.curport, self.proxy_username, self.proxy_password)

    def browsers(self):
        uc.install(
            executable_path=r"C:\Windows\chromedriver.exe",
        )
        opts = ChromeOptions()
        #ua = UserAgent()
        #userAgent = ua.random
        #print(userAgent)
        #userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
        pluginfile = 'proxy_auth_plugin.zip'
        #opts.add_argument(f'user-agent={userAgent}')
        with zipfile.ZipFile(pluginfile, 'w') as zp:
            zp.writestr("manifest.json", self.manifest_json)
            zp.writestr("background.js", self.background_js)
        opts.add_extension(pluginfile)
        opts.add_argument('--log-level=3')
        opts.add_experimental_option("excludeSwitches", ["enable-automation"])
        opts.add_experimental_option('useAutomationExtension', False)
        opts.add_argument("--disable-dev-shm-usage")
        opts.add_argument('--no-sandbox')
        opts.add_argument('--enable-webgl')
        opts.add_argument('--disable-gpu')
        opts.add_argument("--disable-blink-features=AutomationControlled")
        opts.add_argument("start-maximized")
        self.browser = Chrome(options=opts)
        
        self.browser.implicitly_wait(10)
        self.browser.delete_all_cookies()
        sleep(1)

Run the code:

objs = [NewIdentity() for i in range(len(emailids))]
for obj in objs:
    start_time = time.time()
    print("Run Number:",count)
    obj.browsers()

I call this function to request new proxy:

def requestNewProxy(self):
    status = True
    while status:
        r = requests.get("https://xxxxxxx")
        result = r.text.strip()
        print(result)
        if "success" in result:
            self.sendTele("Successfully changed IP - Rotation")
            status = False
        else:
            sleep(15)

Even with all of this : the website says that you cannot have the same register on another account How can I change my identity and behave like im another person each run ?

I tried to change names and folders:

 basename = "mylogfile"
    suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
    filename = "_".join([basename, suffix])
    pluginfile = filename+'.zip'
    newpath = f"C:\\Users\\JeanPierreWaked\\Documents\\{filename}\\{pluginfile}" 
    newnew = f"C:\\Users\\JeanPierreWaked\\Documents\\{filename}"
    print(newpath)
    if not os.path.exists(newnew):
        os.makedirs(newnew)
    #opts.add_argument(f'user-agent={userAgent}')
    with zipfile.ZipFile(newpath , 'w') as zp:
        zp.writestr("manifest.json", manifest_json)
        zp.writestr("background.js", background_js)
    #pluginfile = 'proxy_auth_plugin.zip'
    options.add_extension(newpath)
  • first use `print()` to see if you really have different values in every loop. – furas Nov 05 '21 at 21:29
  • maybe you should use differnt loop `for name in emailids: obj = NewIdentity() ....` – furas Nov 05 '21 at 21:32
  • your last code make no sense - first you create list with instances but later you run loop which doesn't use this instance but it creates again new instance. – furas Nov 05 '21 at 21:33
  • as for me you always write data to the same `proxy_auth_plugin.zip` so finally all browsers may use the same values. And I don't see any `"rotational proxy"` in your code. – furas Nov 05 '21 at 21:35
  • What do you mean use print ? – Jean Pierre Waked Nov 05 '21 at 21:39
  • I updated my code removed 'obj = NewIdentity()' – Jean Pierre Waked Nov 05 '21 at 21:39
  • How to delete all the object and create a entire new object and new browser different from the previous one – Jean Pierre Waked Nov 05 '21 at 21:45
  • I would use some list with different values for different instances and I would send values as `for val in values: obj = NewIdentity(val)` - and `NewIdentity` should use these values to generate different settings in proxy. I would also use module `random` or `tempfile` to create random folder `random_folder/proxy_auth_plugin.zip` or random filename `random_name.zip` for proxy settings. This way every instance should use different settings. – furas Nov 05 '21 at 23:00
  • can you help me doing that ? random stuff please like give me a full code and i will edit it to mine – Jean Pierre Waked Nov 05 '21 at 23:07
  • I tried what you asked and still did not work – Jean Pierre Waked Nov 05 '21 at 23:41

0 Answers0