Selenium Chromedriver ile Proxy Doğrulaması

import os

import zipfile

from tkinter import *

import tkinter as tk

from tkinter import filedialog

from selenium import webdriver

root = tk.Tk()

root.withdraw()

file_path1 = filedialog.askopenfilename(initialdir="/desktop", title="Proxy Dosyasını Seç", filetypes=(("Metin Dosyası", "*.txt"), ("Bütün Dosyalar", "*.*")))

proxydosya = open(file_path1, "r", encoding="utf-8")

proxylist = proxydosya.readlines()

PROXY_HOST = str(proxylist[0].split(':')[0])

PROXY_PORT = str(proxylist[0].split(':')[1])

PROXY_USER = str(proxylist[0].split(':')[2])

PROXY_PASS = str(proxylist[0].split(':')[3])

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):

    path = os.path.dirname(os.path.abspath(__file__))

    chrome_options = webdriver.ChromeOptions()

    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(

        os.path.join(path, 'chromedriver'),

        chrome_options=chrome_options)

    return driver

def main():

    driver = get_chromedriver(use_proxy=True)

    #driver.get('https://www.google.com/search?q=my+ip+address')

    driver.get('https://www.whatismyipaddress.com/')

if __name__ == '__main__':

    main()

arkadaşlar başlıktaki gibi selenium da chromedriver için proxy doğrulamasına ihtiyacım var.
örnek kod da host port user pass bilgilerini oraya (‘127.0.0.1’) gibi eklersem sorunsuz çalışıyor ama proxy dosyasından çekmeye çalışınca bilgileri olmuyor.
Yardım ederseniz sevinirim.

kimsenin bilgisi yok mu bu konuda ?

Hata mesajını görebilirsek, yardımcı olabiliriz.

Ben bir hata goremiyorum, “Proxy Dosyasini Sec” diye bir diyalog aciliyor.

hocam proxy bilgilerini dosyadan çekince proxy çalışmıyor ama değişkenlere manuel olarak (örnek “127.0.0.1” gibi) eklersem oluyor hata bu kodun altına yazmıştım zaten görmemişsiniz sanırım.

Chrome eklenti dosyaları .crx uzantılı oluyor. .zip uzantılı dosya yüklediğiniz için olabilir.

Hayır hocam alakası yok onunla kodları kopyalayıp py dosyasının olduğu dizinde chrome sürümünüzle uyumlu chromedriveri o dizine atıp kodları derlerseniz program çalışacaktır.

değikenleri böyle değil de şu şekilde yaparsam ;

PROXY_HOST = "127.0.0.1"
PROXY_PORT = "10000"
PROXY_USER = "ADMİN"
PROXY_PASS = "PASSWORD"

proxy uygulanmış şekilde chromedriver çalışıyo ama ilk kodda ki gibi bilgileri dosyadan çekince program hata vermeden çalışıyor lakin ISS ip si gözüküyor proxy çalışmıyor yani sorun bu.