python selenium自动登录百度加转窗口

大概思路:

1.定位到登录界面的名字,密码输入框

2.获取当前窗口句柄

3.打印网页title证明句柄以及装换

from selenium import webdriver
import time
driver=webdriver.Chrome()
url=‘https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F&sms=5‘
driver.get(url)
driver.implicitly_wait(10)
driver.find_element_by_xpath("//*[@id=‘TANGRAM__PSP_3__footerULoginBtn‘]").click()  #切换到账号密码登录界面
driver.find_element_by_xpath(‘//*[@id="TANGRAM__PSP_3__userName"]‘).send_keys(‘账号‘)
driver.find_element_by_xpath(‘//*[@id="TANGRAM__PSP_3__password"]‘).send_keys(‘密码‘)
time.sleep(10)
driver.find_element_by_xpath(‘//*[@id="TANGRAM__PSP_3__submit"]‘).click()
time.sleep(5)
windows = driver.window_handles
print(windows)
driver.switch_to.window(windows[-1])//获取窗口句柄
print(driver.title)
driver.quit()

原文地址:https://www.cnblogs.com/chenminyu/p/10947872.html

时间: 2024-08-29 09:42:26

python selenium自动登录百度加转窗口的相关文章

Python + Selenium 自动发布文章(一):开源中国

https://blog.csdn.net/qq_28804275/article/details/80891949 https://blog.csdn.net/qq_28804275/article/details/80891949Python + Selenium 自动发布文章系列:Python + Selenium 自动发布文章(一):开源中国Python + Selenium 自动发布文章(二):简书Python + Selenium 自动发布文章(三):CSDNPython + Sel

【python】自动登录51cto家园

自动登录:http://home.51cto.com 1.分析: 使用httpfox抓取手动登录home.51cto.com的过程,过程如下: 点登录,提交用户名与密码到http://home.51cto.com/index.php?s=/Index/doLogin 这个地址,正确后,他会返回的内容包含很多链接,如第二个图片.然后分别get这些链接.请求完这些链接后,再访问个人主页http://home.51cto.com/index.php?s=/Home/index post成功后服务器返回

Python实现自动登录/登出校园网网关

学校校园网的网络连接有免费连接和收费连接两种类型,可想而知收费连接浏览体验更佳,比如可以访问更多的网站.之前收费地址只能开通包月服务才可使用,后来居然有了每个月60小时的免费使用收费地址的优惠.但是,一旦连接了收费地址而忘记及时断开,60小时会很快用完.     为了节约收费地址的使用时间,采用如下方案:每隔1个小时,都在本机上断开校园网的收费连接,同时连接免费连接,这样,每次手动连接收费连接之后,最多使用1个小时,就会被自动断开. 1. python实现连接/断开网络连接      通过执行p

Python + Selenium 实现登录Office 365

最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解,据说是用了Google的IP,whatever……) 试图研究一下Selenium和WebDriver的关系,看了官方的介绍,先摘录一段有趣的内容: Jump to 2008. The Beijing Olympics mark China’s arrival as a global power,

python模拟自动登录网站(urllib2)

不登录打开网页: import urllib2 request = urllib2.Request('http://www.baidu.com') response = urllib2.urlopen(request).read() print response 保存网页图片(https://www.baidu.com/img/bd_logo1.png): picurl = 'https://www.baidu.com/img/bd_logo1.png' #定义图片的url地址 req = ur

如何利用python+Selenium对登录的验证码进行验证?

python+Selenium自动识别验证码Fg.save_screenshot('D:\HuaYu\image\image.png')ce = Fg.find_element_by_id("ensure") # 具体的id要用F12自行查看print(ce.location)im = Image.open('D:\HuaYu\image\image.png') 根据图片调整位置img = im.crop((860,507,945,532))print(img)img.save('D:

Python+selenium自动循环扔QQ邮箱漂流瓶

Python代码如下: # coding=utf-8 from selenium import webdriver from time import sleep from random import randint def auto_throw(username, password): """自动循环扔瓶子""" driver = webdriver.Chrome() driver.get("https://mail.qq.com&qu

Python+selenium自动循环发邮件

Python源代码如下: # coding=utf-8 from selenium import webdriver from time import sleep from random import randint def auto_throw(target_qq, username, password): """自动循环发邮件""" driver = webdriver.Chrome() driver.get("https://ma

使用selenium自动登录126/163邮箱并发送邮件

我使用的是python2.7.13+selenium ps:几天之前,我曾多次尝试写这段代码,但是在点击写信的步骤时失败了,我想我的问题应该大致是这几点: 1.写信按钮不能直接定位到,同时它的父目录id是动态的,我当时使用xpath定位到了这个动态的id,所以失败是必然的,那么就需要我们继续寻找向上寻找父目录,即多层级的xpath(建议多使用xpath/css)成功率会更高,因为层级越少,那么出现重复的可能越大(比如126写信中的主题的class和搜索框的class是一样的,当然还有很多) 2.