之前都是用phantomjs和selenium模拟浏览器动作的,后来phantomjs不再更新,就转用chrome了

本次模拟登录的网站是中国知网http://login.cnki.net/login/?platform=kns&ReturnURL=http://nvsm.cnki.net/

分析:正常情况下我们登录网页肯定是这样,首先找到输入账号的地方输入账号,找到输入密码的地方输入密码,最后再点击登录键。

我们使用selenium同样也遵循人的这种思路,首先找到输入账号和输入密码的标签节点,然后发送相应的信息过去,最后再找到登录按钮的节点,模拟点击即可。

下面用selenium和chrome浏览器模拟登录,首先F12打开Chrome调试窗口,找到账号输入框和密码输入框的标签节点:

用代码来实现模拟登录:

#!usr/bin/env python
# coding:utf-8 from selenium import webdriver webdriver = webdriver.Chrome() #创建一个空的浏览器
webdriver.get('http://login.cnki.net/login/?platform=kns&ReturnURL=http://nvsm.cnki.net/') #请求网页
name = webdriver.find_element_by_name('TextBoxUserName') #获取用户名节点
name.send_keys('user') #往用户名节点框输入账号,'user'请修改为你的用户名
password = webdriver.find_element_by_name('TextBoxPwd') #获取密码节点
password.send_keys('password') #往密码节点框输入密码,'password'请修改为你的密码
login_button = webdriver.find_element_by_id('Button1') #获取登录按钮的节点
login_button.click() #点击登录按钮

最后登录成功界面如下:

使用selenium模拟知网登录的更多相关文章

  1. (转)request模拟知乎登录(无验证码机制

    原文:http://www.itnose.net/detail/6755805.html import request try: import cookielib #python2版本 except: ...

  2. request模拟知乎登录(无验证码机制)

    import request try: import cookielib #python2版本 except: import http.cookiejar as cookielib #python3版 ...

  3. 【Python】selenium模拟淘宝登录

    # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By f ...

  4. scrapy模拟知乎登录(无验证码机制)

    ---恢复内容开始--- spiders 文件夹下新建zhihu.py文件(从dos窗口中进入虚拟环境,再进入工程目录之后输入命令 scrapy genspider zhihu www.zhihu.c ...

  5. Python模拟知乎登录

    # -*- coding:utf-8 -*- import urllib import urllib2 import cookielib import time from PIL import Ima ...

  6. 新版知乎登录之post请求

    前言 在上一篇文章中给大家讲解了requests发送post请求的几种方式,并分析了一些使用陷阱. 疑惑 在文章发表之后,有朋友给我留言说,知乎登录就没有使用提交Form表单(application/ ...

  7. 使用selenium模拟登录知乎

    网上流传着许多抓取知乎数据的代码,抓取它的数据有一个问题一定绕不过去,那就是模拟登录,今天我们就来聊聊知乎的模拟登录. 获取知乎内容的方法有两种,一种是使用request,想办法携带cookies等必 ...

  8. 4 使用Selenium模拟登录csdn,取出cookie信息,再用requests.session访问个人中心(保持登录状态)

    代码: # -*- coding: utf-8 -*- """ Created on Fri Jul 13 16:13:52 2018 @author: a " ...

  9. 模拟学信网登录,Cookie 序列化,在反序列化之后不能用的问题

    昨天和今天在模拟学信网登录,然后抓取用户的信息数据的时候发现一直登录不成功, 登录页面,https://account.chsi.com.cn/passport/login?service=http% ...

随机推荐

  1. POJ3623 Best Cow Line, Gold 【后缀数组】

    最好的牛线,金 时间限制: 5000MS   内存限制: 65536K 提交总数: 5917   接受: 2048 描述 FJ即将把他的ñ(1≤ ñ ≤30,000)头牛竞争一年一度的"年度 ...

  2. 理解[].forEach.call()

    例子: let cols = document.querySelectorAll('ul li') [].forEach.call(cols, function (col, index) { // T ...

  3. GROUP_CONCAT(expr)

    This function returns a string result with the concatenated non-NULL values from a group. It returns ...

  4. source改变当前路径

    转摘自:http://hi.baidu.com/homappy/item/90e416525d2faf958c12edb7 Shell 脚本执行有三种方法 bash 脚本名 sh 脚本名 chmod ...

  5. Things To Do Before NOI2017

    TC div1 10套 数据结构 25题 网络流 10题 字符串 20题 数学 15题 图论 15题 计算几何 5题 提交答案 5题 嗯...先这些吧... 以上所有题目,博客都会有更新--- NOI ...

  6. linux基础(2)

    Linux基础题 作业一:1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”useradd natashagroupmod -g 555 natashauser ...

  7. codeforces 854 problem E

    E. Boredom Ilya is sitting in a waiting area of Metropolis airport and is bored of looking at time t ...

  8. spoj p104 Matrix-Tree定理

    这个问题就是经典的生成树记数问题,题目为spoj p104 highway. 首先我们引入Matrix-Tree定理,由kirchhoff证明,定理的概述为,对于图G,我们定义若干个矩阵, D[G], ...

  9. js中typeof 与instanceof的区别

    1.typeof 用来检测给定变量的数据类型,其返回的值是下列某个字符串: "undefined":变量未定义 "boolean":变量为布尔类型 " ...

  10. Swift “ambiguous use of operator '>'”

    http://stackoverflow.com/questions/25458548/swift-ambiguous-use-of-operator 3down votefavorite   I h ...