webdrive www2.baidu.com 定位不到元素
#coding:utf-8from selenium import webdriver
import time,os,sys
def withoutCookieLogin(url):
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=options)
options.add_argument('lang=zh_CN.UTF-8')
options.add_argument("user-agent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'")
driver.maximize_window()
driver.get(url)
driver.find_element_by_class_name('tab-log-type pull-right').click()
driver.find_element_by_id('uc-common-account').clear()
driver.find_element_by_id('uc-common-account').send_keys("name")
driver.find_element_by_id('ucsl-password-edit').clear()
driver.find_element_by_id('ucsl-password-edit').send_keys("password")
authCode = input('输入验证码')
driver.find_element_by_id('uc-common-token').send_keys(authCode)
driver.find_element_by_id(u'submit-form').click()
return driver
driver = withoutCookieLogin("http://cas.baidu.com/?tpl=www2&fromu=http%3A%2F%2Fwww2.baidu.com%2F")`请输入代码`
其他网站都没问题,凤巢后台搜寻不到element,有注意到打开的chrome浏览器是看不到element,右键对body进行edit as html,然后才能看到,python新手,求大手子指教,感谢!
回答:
注意报错“Compound class names not permitted”,多个class是不被允许的,调用find_element_by_class_name()只接受一个class。
可以用xpath替代,这样写:
driver.find_element_by_xpath("//*[@class='tab-log-type' or @class='pull-right']")
回答:
感谢指证 另外不仅是第一个错误 下面的element也都是找不到的
以上是 webdrive www2.baidu.com 定位不到元素 的全部内容, 来源链接: utcz.com/a/157852.html