Python Gelişimimde Yardimci Olacak?
2
●132
- 18-01-2023, 22:46:38
from selenium import webdriver proxy = "proxy_adres:proxy_port" chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--proxy-server=http://' + proxy) browser = webdriver.Chrome(chrome_options=chrome_options) browser.get("http://example.com")şöyle bir örnek var proxy kısmını file ile ekleyebilirsin - 18-01-2023, 23:08:52auth yani k.adı şifre ile proxy kullanacaksan
çalışan kodumu paylaşayım. selenium chrome üzerinde çalışır. mantığı proxyne göre eklenti hazırlaıp chrome eklenti ile başlatır bu sayede %100 proxy ile girmiş olursun
import zipfile pluginfile = "proxy_eklentisi.zip def Eklentiyap(PROXY_HOST,PROXY_PORT,PROXY_USER,PROXY_PASS ): 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) with zipfile.ZipFile(pluginfile, 'w') as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js)yukarıdaki ile proxy içine eklenmiş eklenti dosyanı oluşturup aşağıdaki kod ile selenium driverına eklemen yeterli
chrome_options.add_extension(pluginfile)