python和selenium配合自动登录百度

参考:

下载chromedriver地址:http://chromedriver.storage.googleapis.com/index.html或者http://npm.taobao.org/mirrors/chromedriver/

配置chromedriver:https://jingyan.baidu.com/article/f7ff0bfcdd89ed2e27bb1379.html

我的chrome版本:78.0.3904.97(64位)可以使用win32的chromedriver

chromedriver对照表:https://blog.csdn.net/BinGISer/article/details/88559532

selenium使用的基本指导:https://www.jianshu.com/p/87aeb3341a83

selenium处理弹出框:https://www.cnblogs.com/simran/p/9240917.html

selenium自动登录百度:https://jingyan.baidu.com/article/1612d500e8be56e20e1eee83.html

win8+pycharm+python3.6

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time


# 我写的方法:登录百度
url = "https://www.baidu.com/"
# url = "https://music.163.com/#/my/m/music/playlist?id=809646899"
automation = webdriver.Chrome()
automation.get(url)
automation.find_element_by_xpath('//*[@id="u1"]/a[7]').click()
ele_id = "TANGRAM__PSP_10__footerULoginBtn"
param = (By.ID, ele_id)
WebDriverWait(automation,10).until(EC.visibility_of_element_located(param))
automation.find_element_by_id(ele_id).click()

ele_id_password = "TANGRAM__PSP_10__userName"
param_password = (By.ID, ele_id_password)
WebDriverWait(automation,10).until(EC.visibility_of_element_located(param_password))
input_password = automation.find_element_by_id(ele_id_password)
input_password.send_keys('xxx')

ele_id_password = "TANGRAM__PSP_10__password"
# param_password = (By.ID, ele_id_password)
# WebDriverWait(automation,10).until(EC.visibility_of_element_located(param_password))
input_password = automation.find_element_by_id(ele_id_password)
input_password.send_keys('xxx')

ele_id_submit = "TANGRAM__PSP_10__submit"
# param_submit = (By.ID, ele_id_submit)
# WebDriverWait(automation,10).until(EC.visibility_of_element_located(param_submit))
automation.find_element_by_id(ele_id_submit).click()
# time.sleep(10)
# automation.quit()

time.sleep(60)
ele_class = "s_ipt"
input_content = automation.find_element_by_class_name(ele_class)
input_content.send_keys('华为mate30')
input_content.send_keys(Keys.ENTER)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值