簡體   English   中英

帶有硒的 Python browsermob 代理

[英]Python browsermob proxy with selenium

我正在嘗試導入 Google HAR 文件,但我寫的這段代碼給了我這個錯誤:

AttributeError: 'ProxyManger' object has no attribute '_ProxyManger__server'. Did you mean: '_ProxyManger__BMP'?

我的代碼:

import pprint
import time

from browsermobproxy import Server
from selenium import webdriver

class ProxyManger:

    __BMP = "C:/Users/Ender/Desktop/browsermob-proxy-2.1.4/bin/browsermob-proxy.bat"

    def __int__(self):
        self.__server = Server(ProxyManger.__BMP)
        self.__client = None

    def start_server(self):
        self.__server.start()
        return self.__server

    def start_client(self):

        self.__client = self.__server.create_proxy(params={"trustAllServers": "true"})
        return self.__client

    @property
    def client(self):
        return self.__client
    @property
    def server(self):
        return self.__server
if "__main__" == __name__:
    proxy = ProxyManger()
    server = proxy.start_server()
    client = proxy.start_client()
    client.new_har("google.com")
    print(client.proxy)
    options = webdriver.ChromeOptions()
    options.add_argument("--proxy-server={}".format(client.proxy))
    driver = webdriver.Chrome(chrome_options=options)
    driver.get("https://www.google.com/")
    time.sleep(3)

    pprint.pprint(client.har)
    server.stop()

我不明白我哪里出錯了,問題的根源是什么,我需要如何解決? 如果你能幫忙,我會很高興。 祝你今天過得愉快

__init__函數寫錯了,你有__int__它應該是__init__因為它沒有進入 init 函數它沒有創建 _server 屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM