-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchromeprompt.py
More file actions
92 lines (83 loc) · 2.39 KB
/
chromeprompt.py
File metadata and controls
92 lines (83 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from selenium import webdriver
from random import choice
from webdriver_manager.chrome import ChromeDriverManager
import zipfile,os
from selenium import webdriver
from time import sleep
from selenium import webdriver
import os
from bs4 import BeautifulSoup
import requests
from random import choice
from webdriver_manager.chrome import ChromeDriverManager
import praw
import pprint
import random
import requests
from http_request_randomizer.requests.proxy.requestProxy import RequestProxy
import json
from proxydriver import get_chromedriver
from fake_useragent import UserAgent
ua = UserAgent()
userAgent = ua.random
src = 'https://stackoverflow.com/questions/55582136/how-to-set-proxy-with-authentication-in-selenium-chromedriver-python'
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"
}
"""
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']
);
""" % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
def get_chromedriver(use_proxy=False, user_agent=None):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)
if use_proxy:
pluginfile = 'proxy_auth_plugin.zip'
with zipfile.ZipFile(pluginfile, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
chrome_options.add_extension(pluginfile)
if user_agent:
chrome_options.add_argument('--user-agent=%s' % user_agent)
driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=chrome_options)
return driver