func.py
baidu_login.py中(如有验证码,需要手动输入)
# 导入webdriver
import os
import time
import re
from lxml import etree
from selenium import webdriver
from func import base642str, str2base64
# 将mm隐匿化
# import sys
# print(str2base64("123456"))
# str1_base64="MTIzNDU2"
# print(base642str(str1_base64))
# sys.exit()
print('000-正在启用selenium...')
# 调用环境变量指定的PhantomJS浏览器创建浏览器对象
driver = webdriver.Chrome(r'D:\zzl\new_work\tmp\test01\baidulogin\chromedriver.exe')
print('000-OK')
#
url = 'https://passport.baidu.com/v2/?login'
print('111-selenium正在请求页面:%s' % url)
driver.get(url) # get方法请求页面,获取响应
print('111-请求OK')
print("打印标题")
print(driver.title)
# 点击账号和密码登录
input_box0 = driver.find_element_by_xpath("//p[@id='TANGRAM__PSP_3__footerULoginBtn']")
input_box0.click()
print('222-selenium正在填写表单...')
time.sleep(1)
account = "abcdef"
pwd = "MTIzNDU2"
verify_code = "1234"
input_box1 = driver.find_element_by_xpath("//input[@id='TANGRAM__PSP_3__userName']")
input_box1.send_keys(account)
time.sleep(0.5)
input_box2 = driver.find_element_by_xpath("//input[@id='TANGRAM__PSP_3__password']")
input_box2.send_keys(base642str(pwd))
time.sleep(0.5)
# 判断是