self_example/Spider/Chapter09_代理的使用/代理池的维护/ProxyPool/proxypool/schemas/proxy.py

31 lines
577 B
Python

from attr import attrs, attr
@attrs
class Proxy(object):
"""
proxy schema
"""
host = attr(type=str, default=None)
port = attr(type=int, default=None)
def __str__(self):
"""
to string, for print
:return:
"""
return f'{self.host}:{self.port}'
def string(self):
"""
to string
:return: <host>:<port>
"""
return self.__str__()
if __name__ == '__main__':
proxy = Proxy(host='8.8.8.8', port=8888)
print('proxy', proxy)
print('proxy', proxy.string())