定義Proxy類, 繼承object實(shí)現(xiàn)__init__方法, 負(fù)責(zé)初始化, 包含如下字段:ip: 代理的IP地址port: 代理IP的端口號(hào)protocol: 代理IP支持的協(xié)議類型,http是0, https是1, https和http都" />
時(shí)間:2023-02-10 17:15:01 | 來源:建站知識(shí)
時(shí)間:2023-02-10 17:15:01 來源:建站知識(shí)
目標(biāo)
: 定義代理IP的數(shù)據(jù)模型類步驟
:Proxy
類, 繼承object__init__
方法, 負(fù)責(zé)初始化, 包含如下字段:__str__
方法, 返回?cái)?shù)據(jù)字符串代碼
:# 代理模型類, 用于封裝代理相關(guān)信息class Proxy(object): def __init__(self, ip, port, protocol=-1, nick_type=-1,speed=-1, area=None, score=50, disable_domains=[]): self.ip = ip # IP self.port = port # 端口號(hào) self.protocol = protocol # 代理IP支持協(xié)議類型,http是0, https是1, https和http都支持是2 self.nick_type = nick_type # 匿名程度:高匿:0,匿名: 1, 透明:0 self.speed = speed # 速度, 單位s self.area = area # 所在地區(qū) self.score = score # 代理IP的評(píng)分, 在進(jìn)行代理可用性檢查的時(shí)候, 每遇到一次請(qǐng)求失敗就減1份, 減到0的時(shí)候從池中刪除. 如果檢查代理可用, 就恢復(fù)默認(rèn)分值 self.disable_domains = disable_domains def __str__(self): # 返回?cái)?shù)據(jù)字符串 return str(self.__dict__)
總結(jié)
關(guān)鍵詞:模型,數(shù)據(jù),代理,定義
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。