爬取网站时在使用
show_Full_img = “document.getElementsByClassName(‘geetest_canvas_fullbg’[0].style.display=‘block’”
self.browser.execute_script(show_Full_img)
获取原图时,出现以下错误:
seleniummon.exceptions.JavascriptException: Message: javascript error: Cannot read property ‘style’ of undefined
网上搜了许久,也没找到答案。发现自己犯了个简单的错误,在验证码图片出现时,没有加上**time.sleep(0.5)**这一等待条件,元素还没出现!加上之后就可以了!
当然,出现 ‘style’ of undefined也可能是其他情况,网上有很多答案,在这里就不赘述,只是提供一种解决方案。

——————————————————————————————————————————————
微信关注号:python爬虫机器学习深度学习

更多推荐

selenium还原图片时出现javascript error: Cannot read property 'style' of undef