当前位置:网站首页>Selenium basic knowledge automatically login Baidu Post Bar
Selenium basic knowledge automatically login Baidu Post Bar
2022-07-24 07:36:00 【everyone_ yi】
""" Dialog processing Floating pop-up dialog Such as login box or other functions iframe Baidu post bar : 1. single click " Sign in " link , The login box will pop up 2. Click... In the login box " User name login " Options , Show the real login interface 3. Fill in account and password , single click " Sign in " Button """
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
data={
'url':'https://tieba.baidu.com/index.html',
'first_btn_classname':'u_menu_item',
'show_account_login_id':'TANGRAM__PSP_4__footerULoginBtn',
'usename_id':'TANGRAM__PSP_4__userName',
'password_id':'TANGRAM__PSP_4__password',
'login_btn_id':'TANGRAM__PSP_4__submit',
'username':'*********',
'password':'**********
'
}
driver = webdriver.Edge()
driver.get(data['url'])
# Click on the login link
# first_btn = driver.find_element_by_css_selector("#com_userbar > ul > li.u_login > div > a")
first_btn = driver.find_element(by=By.CLASS_NAME,value=data['first_btn_classname'])
first_btn.click()
time.sleep(2)
# Click on 【 User name login 】 Options
show_account_login = driver.find_element(by=By.ID,value=data['show_account_login_id'])
show_account_login.click()
time.sleep(2)
# Fill in account and password
# TANGRAM__PSP_10__userName
# TANGRAM__PSP_10__password
driver.find_element(by=By.ID,value=data['usename_id']).send_keys(data['username'])
time.sleep(2)
driver.find_element(by=By.ID,value=data['password_id']).send_keys(data['password'])
time.sleep(2)
driver.find_element(by=By.ID,value=data['login_btn_id']).click()
There is only one problem, which is the first step Click on the login link Use classname When positioning Because there can be no spaces So it will match the first one In this page The first one matched will be other buttons Will go wrong
This button on Baidu homepage class by u_menu_item u_menu_bdhome j_u_menu_bd_home_link
In the code, it is written in front of the login button So I will match Baidu's button first
change to the use of sth. u_login To match Or use elements Search and select the second result is also ok 

Just change it
data={
'url':'https://tieba.baidu.com/index.html',
'first_btn_classname':'u_login',
'show_account_login_id':'TANGRAM__PSP_4__footerULoginBtn',
'usename_id':'TANGRAM__PSP_4__userName',
'password_id':'TANGRAM__PSP_4__password',
'login_btn_id':'TANGRAM__PSP_4__submit',
'username':'*****',
'password':'*****'
}
There will also be the problem of SMS verification code behind this It will be solved later
边栏推荐
- 游戏三子棋
- Feature Selective Anchor-Free Module for Single-Shot Object Detection
- 无法自动装配,未找到“RedisTemplate类型的Bean
- 24. Global event bus
- AMD64 (x86_64) architecture ABI document: upper
- requests-爬虫多页爬取肯德基餐厅位置
- Bookkeeping app: xiaoha bookkeeping 1 - production of welcome page
- Simple installation of sqli Labs
- PHP link log scheme
- Vulnhub DC1
猜你喜欢

win10声音图标有个没有声音

Advanced part of C language I. data storage

C language advanced part II Pointer

Jenkins 详细部署

C language advanced part III. string functions and memory operation functions

从CIA看常见网络攻击(爆破,PE,流量攻击)

Customization or GM, what is the future development trend of SaaS in China?

Buffer overflow vulnerability of network security module B in national vocational college skills competition

Source code analysis of Nacos configuration center

Introduction to C language III Array 4. Operators
随机推荐
Introduction to C language
Sword finger offer special assault edition day 8
Give a string ① please count the number of times each letter appears ② please print the pair with the most letters
【信息系统项目管理师】第七章 复盘成本管理知识架构
Arduino在不同主频下稳定支持的TTL串口速率
游戏三子棋
My creation anniversary
Jackson parsing JSON detailed tutorial
【Pytorch】Dataset_ DataLoader
Advanced part of C language VI. file operation
[sklearn] RF cross validation out of bag data parameter learning curve grid search
AMD64 (x86_64) architecture ABI document: upper
php 转义字符串
MySQL语句
C language advanced part III. string functions and memory operation functions
[tips] a simple method to create a version control project
【HiFlow】腾讯云HiFlow场景连接器实现校园信息管理智能化
China trichlorosilane Market Forecast and Strategic Research Report (2022 Edition)
Notes on the basics of using parameters in libsvm (1)
numpy.cumsum