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. 這里調(diào)用 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.這里我調(diào)用open(self)實例里面的屬性 self.driver.find_element_by_id()就不會報錯,同樣是調(diào)用實例,這是為什么呢?
總結(jié)
以上是生活随笔為你收集整理的python类属性的调用方法_问一个关于PYTHON类属性调用方法的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python测试脚本截图_seleniu
- 下一篇: python 购物车程序_python_