基本信息
源码名称:python+selenium+phantomjs 模拟自动登陆discuz论坛 示例源码
源码大小:17.46M
文件格式:.zip
开发语言:Python
更新时间:2018-06-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
下图为登陆成功后的结果
#coding:utf-8 from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait # WebDriverWait的作用是等待某个条件的满足之后再往后运行 import time import sys driver = webdriver.PhantomJS(executable_path=r'D:\Projects\PythonProjects\PythonApplication1\PythonApplication1\phantomjs-2.1.1-windows\bin\phantomjs.exe') # 构造网页驱动 driver.get('http://www.yingxiaobu.com/forum.php') # 打开网页 driver.find_element_by_xpath('//*[@id="ls_username"]').send_keys('你的用户名') driver.find_element_by_xpath('//*[@id="ls_password"]').send_keys('你的密码') #driver.get_screenshot_as_file('验证码.jpg') # 截取当前页面的图片 #input_solution = input('请输入验证码 :') 手工打码 #driver.find_element_by_xpath('//input[@name="captcha"]').send_keys(input_solution) #time.sleep(2) driver.find_element_by_xpath('//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button').click() # 表单的提交 表单的提交,即可以选择登录按钮然后使用click方法,也可以选择表单然后使用submit方法 sreach_widonw = driver.current_window_handle # 用来定位当前页面 # driver.find_element_by_xpath('//button[@class="sign-button submit"]').click() try: dr = WebDriverWait(driver,5) #dr.until(lambda the_driver: the_driver.find_element_by_xpath('//a[@class="zu-side-login-box"]').is_displayed()) if driver.find_element_by_xpath('//*[@id="um"]/p[1]/strong/a'): print('登录成功') except: print('登录失败') time.sleep(5) driver.save_screenshot('screen_shoot.jpg') #截取当前页面的图片 sys.exit(0) driver.quit() #退出驱动