新版豆瓣模拟登录(selenium+Firefox)

注意:

1.要先切换到登录密码所在的框架,默认打开的在短信登录/注册,要切换到"密码登录"来

driver.switch_to(find_elements_by_tag_name("iframe")[0])

 2.切换来之后,要点击一下"密码登录"这个按钮,说明以后就是在这个框架上了

bottom1 = driver.find_element_by_xpath('/html/body/div[1]/div[1]/ul[1]/li[2]    ')
 #点击
bottom1.click()

3.下面是完整代码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#导包
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#用的是火狐浏览器
driver = webdriver.Firefox()
#登录豆瓣网
driver.get("http://www.douban.com/")

#切换到登录框架中来
driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
#点击"密码登录"
bottom1 = driver.find_element_by_xpath('/html/body/div[1]/div[1]/ul[1]/li[2]')
bottom1.click()

#输入密码账号
input1 = driver.find_element_by_id("username")
input1.clear()
input1.send_keys("******")

input2 = driver.find_element_by_id('password')
input2.clear()
input2.send_keys("*******")

#登录
bottom = driver.find_element_by_class_name('account-form-field-submit ')
bottom.click()


4.登录后的页面

猜你喜欢

转载自blog.csdn.net/weixin_42618420/article/details/89313831