请指教一下,豆瓣的元素submit信息如图:代码如下: click、ENTER、RETURN、SPACE统统没用from selenium import webdriver # 导入seleniumfrom selenium.webdriver.common.keys import Keysdef loginZhihu():
loginurl = 'https://accounts.douban.com/login'
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
driver.get(loginurl)
driver.find_element_by_name('form_email').clear()
driver.find_element_by_name('form_email').send_keys(u'5467878878')
driver.find_element_by_name('form_password').clear()
driver.find_element_by_name('form_password').send_keys(u'454354543543')
captcha = driver.find_element_by_id('captcha_image')
submit = driver.find_element_by_css_selector('input[class="bn-submit"]')
if captcha:
captcha_field = driver.find_element_by_id('captcha_field')
text = input("请输入验证码:")
captcha_field.send_keys(text)
submit.send_keys(Keys.RETURN)
else:
submit.send_keys(Keys.RETURN)
1 回答
九州编程
TA贡献1785条经验 获得超4个赞
根据你的截图,submit 按钮并没有被选中,应改成
-submit = driver.find_element_by_css_selector('input[class="bn-submit"]') # 获取提交按钮 +submit = driver.find_element_by_css_selector('input[class="btn-submit"]') # 获取提交按钮
添加回答
举报
0/150
提交
取消