码迷,mamicode.com
首页 > Web开发 > 详细

豆瓣模拟登录(双层html)

时间:2019-04-17 23:31:38      阅读:486      评论:0      收藏:0      [点我收藏+]

标签:数据   password   模拟   页面   登录页面   tps   嵌套   wrap   html   

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author tom
import time
from selenium import webdriver

#构造浏览器,请求数据
bro=webdriver.Chrome()
bro.get(https://www.douban.com/)
time.sleep(2)

#他的登录页面是双层嵌套的,要先转入里面那个页面,标签才能定位到
iframe=bro.find_element_by_tag_name(iframe)
bro.switch_to_frame(iframe)

#点击密码登录
pslogin=bro.find_elements_by_css_selector(body > div.account-body.login-wrap.login-start.account-anonymous > div.account-body-tabs > ul.tab-start > li.account-tab-account)[0]
print(pslogin)
print(type(pslogin))
pslogin.click()

time.sleep(2)

#填入密码
bro.find_element_by_id(username).send_keys(xxx)
bro.find_element_by_id(password).send_keys(xxx)

time.sleep(2)
#点击登录
btn=bro.find_element_by_xpath(//a[@class="btn btn-account btn-active"])
btn.click()

cookies={i[‘name‘]:i[‘value‘]for i in bro.get_cookies()}
print(cookies)

time.sleep(3)
bro.quit(
 

 

豆瓣模拟登录(双层html)

标签:数据   password   模拟   页面   登录页面   tps   嵌套   wrap   html   

原文地址:https://www.cnblogs.com/tjp40922/p/10726931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!