python27+selenium+Phantomjs登录京东

selenium处理验证码还不会搞,之后再更新有验证码的登录

# _*_coding:utf-8_*_
from selenium import webdriver
import time
import requests
s = requests.session()
from lxml import etree

start_url = "https://passport.jd.com/uc/login?ltype=logout"
#driver = webdriver.Firefox()
driver = webdriver.PhantomJS()
def get_Login_Cookie():
    driver.get(start_url)
    time.sleep(1)
    elem_name = driver.find_element_by_name("loginname")
    elem_password = driver.find_element_by_name("nloginpwd")
    elem_name.clear()
    elem_password.clear()
    elem_name.send_keys("账号")
    elem_password.send_keys("密码")
    elem_login = driver.find_element_by_id("loginsubmit")
    elem_login.click()
    time.sleep(1)
    print driver.current_url
    cookies = driver.get_cookies()
    #print cookies
    cookie = []
    for item in cookies:
        cookie.append(item['name'] + '='  + item['value'])
    c = ';'.join(cookie)
    return c



def islogin():
    home_url = "https://home.jd.com/"
    page = s.get(home_url).text
    #print page
    dom = etree.HTML(page)
    Me = dom.xpath('/html/body/div[4]/div/div/div[2]/div[1]/div[2]/div[1]/div[2]/div[1]/a/text()')
    if Me:
        print "Cookie登录成功!"
    #print Me

if __name__ == "__main__":
    c = get_Login_Cookie()
    s.headers.update({"cookie":c})
    islogin()








  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值