python类属性的调用方法_问一个关于PYTHON类属性调用方法的问题

def baidu(self):

self.APP_ID='2180368'

self.API_KEY='EYAvb2oTaGa9oSNs5S2yx6v'

self.SECRET_KEY='dmgvBELGq9cMvk2uSPqLUaLUpEng02D'

self.aip=AipOcr(self.APP_ID,self.API_KEY,self.SECRET_KEY) #1.这里定义的self.aip 3. 如果 我把这个self.aip定义在__init__(self)里面就不会报错。

def open(self):

self.url='http://www.xxgame.net/account/login'

self.driver=webdriver.Chrome()

self.driver.get(self.url)

time.sleep(5)

self.driver.find_element_by_id('UserName').send_keys('13600533179')

self.driver.find_element_by_id('Password').send_keys('hahawangzi1')

self.driver.save_screenshot('window.png')

self.cd =self.driver.find_element_by_id('imgValIDAteCode')

print(self.cd.location)

self.left=self.cd.location['x']

self.top=self.cd.location['y']

self.right=self.cd.size['width']+self.left

self.height=self.cd.size['height']+self.top

self.im=Image.open("window.png")

self.img=self.im.crop((self.left,self.top,self.right,self.height))

self.img.save('w2.png')

self.duqu()

def duqu(self):

with open('w2.png','rb') as fb:

self.img1 =fb.read()

self.result = self.aip.basicGeneral(self.img1)#注意看这里2. 这里调用 self.aip这个属性会报错,找不到这个属性 在看上面3

self.obj=json.dumps(self.result)

self.obj2=json.loads(self.obj)

self.pan=re.compile("\d+")

print(self.result)

print(str(re.findall(self.pan,str(self.obj2['words_result']))).strip('[]').strip("''"))

self.yzm=str(re.findall(self.pan,str(self.obj2['words_result']))).strip('[]').strip("''")

self.driver.find_element_by_id("LAY-user-login-vercode").send_keys(self.yzm)

self.driver.find_element_by_class("layui-btn layui-btn-fluid").click() # 看这里4.这里我调用open(self)实例里面的属性 self.driver.find_element_by_id()就不会报错,同样是调用实例,这是为什么呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值