Selenium与phantomJS 登入豆瓣 有bug

# -*- coding:utf-8 -*-

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys
import time 
print 1
# 创建一个无界面的对象
driver = webdriver.PhantomJS()

driver.get("https://www.douban.com/accounts/login")
driver.save_screenshot("main.png")
print 2
print driver.page_source

# 输入账号密码
driver.find_element_by_name("form_email").send_keys("214769277@qq.com")
driver.find_element_by_name("form_password").send_keys("a123456")
driver.save_screenshot("code.png")

code = raw_input("请输入验证码:")
driver.find_element_by_name("captcha-solution").send_keys(code)

# 模拟点击登入
driver.find_element_by_xpath("//div/input[@type='submit']").click()

# 等待3秒
time.sleep(3)

# 生成登入后快照
driver.save_screenshot("douban.png")

# 保存页面html
with open("douban.html", "w") as f:
    f.write(driver.page_source)
# 关闭浏览器    
driver.quit()

 

posted @ 2017-10-19 02:54  cuzz_z  阅读(549)  评论(0编辑  收藏  举报