通过模拟浏览器获取cookies
来源:互联网 发布:三国杀制作软件 编辑:程序博客网 时间:2024/05/19 23:04
def set_login_params_Job51(self): """ 51Job登录配置 2017-06-06 17:36 由于51Job的验证码是中文,所以这里仅仅采用chromeDriver打开Chrome浏览器, 自行在页面输入用户密码进行验证(60s内输入用户密码和验证码),然后程序通过定期访问页面来保持页面登录状态 :return: """ # 用户名、密码,中文字符前要加u字符,不然send_keys函数会出错 self.vipname = u"*************" self.username = "*************" self.password = "************" # 登录链接 self.login_url = 'http://ehire.51job.com/MainLogin.aspx' # 登录后打开的新地址 self.open_url = 'http://ehire.51job.com/Jobs/JobSearchPost.aspx?IsHis=N' # 验证码地址 self.vcode_url = None # 登录框信息路径 # 选着账户密码登录 self.clickAccountLoginXpath=None self.input_name_xpath=None self.input_pwd_xpath = None self.input_check_xpath = None self.input_vcode_xpath =None self.input_btn_xpath=None
def ChromeWebDriver(self): """默认打开百度页面""" executable_path='../spider/driver/chromedriver.exe' self.driver=webdriver.Chrome(executable_path=executable_path) self.driver.get('https://www.baidu.com/') self.driver.set_window_size(1366,768) return self.driver
def saveCookie(self): self.cookies = self.driver.get_cookies() if self.cookies: with open(self.cookiesFile, 'w') as f: pickle.dump(self.cookies, f) result = True print '已将cookies对象写入文件 {0}...'.format(self.cookiesFile) else: print '登录失败' result=False return result
def UIloginJob51(self): """51Job Chrome界面登录""" print '=' * 50 print '{0} 51Job Chrome界面登录...'.format(self.getCurrtime()) # 设置51Job登录参数 self.set_login_params_Job51() # 打开chrome浏览器窗口 self.ChromeWebDriver() tryTime = 0 login = 'not ok' while login != 'ok': tryTime += 1 # 输入51Job登录地址 self.driver.get(self.login_url) vip_name = self.driver.find_element_by_xpath("""//input[@name="txtMemberNameCN"]""") user_name = self.driver.find_element_by_xpath("""//input[@name="txtUserNameCN"]""") pwd = self.driver.find_element_by_xpath("""//input[@name="txtPasswordCN"]""") vip_name.send_keys(self.vipname) time.sleep(1) user_name.send_keys(self.username) time.sleep(1) pwd.send_keys(self.password) time.sleep(1) # 在界面上输入用户密码和验证码并点击登录 # 当你确定正常登录后请输入:ok login = raw_input("确定已经登录请输入ok,否则随便输入\n") print '你输入了:{0}'.format(login) if login == 'ok': print '{0} 登录成功,即将保存cookie...'.format(self.getCurrtime()) self.saveCookie() else: print '{0} 登录失败,输入用户密码登录,当前尝试登录{1}次...'.format(self.getCurrtime(), tryTime) time.sleep(3) self.driver.close()
阅读全文
0 0
- 通过模拟浏览器获取cookies
- selenium2java通过请求接口获取并向浏览器插入cookies
- selenium2java通过请求接口获取并向浏览器插入cookies
- 通过selenium来模拟登录,获取登录后的cookies
- 通过cookielib获取cookies
- 获取本地浏览器中的 Cookies
- 浏览器cookies 和其路径获取
- python获取浏览器cookies登录熊猫tv
- c#模拟请求获取与设置cookies
- Sina微博模拟登录获取Cookies
- java 通过模拟cookies登陆新浪微博
- httpwebrequest 模拟登录 获取cookies 以前的代码,记录备忘!
- Sina微博模拟登录获取Cookies (v1.3.16)
- httpwebrequest 模拟登录 获取cookies 以前的代码,记录备忘!
- python模拟新浪微博登陆之获取cookies
- PHP CURL获取cookies模拟登录…
- 获取cookies
- 通过浏览器获取用户地理位置
- JavaScript中的小技巧和注意点(一)
- Android自定义控件:做一个拼图游戏
- 【C++】指针测试,单步调试,细观指针本身和指针变量所有变化
- Pandas数据特征分析
- EJB到底是什么
- 通过模拟浏览器获取cookies
- 基于Flume的美团日志收集系统(一)架构和设计
- 微信分享我的好友,分享朋友圈需要注意的问题
- 线程池
- 程序员面试金典:集合栈、用两个栈实现队列
- Android7.0适配教程,心得
- 有两个不同list,需要对比两个list内容且输出差异的内容
- 存储数据——HeadFirst JavaScript第二章
- 解释性语言