我很乐意在注册页面上注册,但我的目标是每次执行循环时我都想要一个新的 chrome 配置文件和 cookie 和代理,就像连接的新设备一样 我使用旋转代理,我确定我的问题不是这里的代理
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)
运行代码:
objs = [NewIdentity() for i in range(len(emailids))]
for obj in objs:
start_time = time.time()
print("Run Number:",count)
obj.browsers()
我调用这个函数来请求新的代理:
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)
即使有这一切:网站说你不能在另一个帐户上拥有相同的注册 我怎样才能改变我的身份并表现得像我每次运行的另一个人?
我试图更改名称和文件夹:
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)