#coding:utf-8
#author:jwong

import requests
import urllib2
import re
from bs4 import BeautifulSoup as bs

def login():
	s = requests.Session()
	login_url = 'http://192.168.21.122/dvwa/login.php'
	content = s.get(login_url)
	pattern = re.compile("name='user_token' value='(.*?)'")
	tokens = re.findall(pattern,content.text)
	token = tokens[0]

	data = {
			'username':'admin',
			'password':'password',
			'Login':'Login',
			'user_token':token}
	headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0'}
	res = s.post(login_url,data,headers=headers)
	re.compile('')

	spider(s)

def spider(s):

	url_open = 'http://192.168.21.122/dvwa/index.php'
	response = s.get(url_open)
	soup = bs(response.text)

	info = soup.find_all('a')
	print info
	exit()

if __name__ == '__main__':
	login()

  

requests模拟登录的更多相关文章

  1. Python requests模拟登录

    Python requests模拟登录 #!/usr/bin/env python # encoding: UTF-8 import json import requests # 跟urllib,ur ...

  2. Python 3.3.3 使用requests模拟登录网站

    在模拟登录上,requests确实比python标准库中的相关模块更加简洁. 假设你需要去爬一组页面(targetUrls),而这些页面要登录才能进行访问.那么requests能够提供一种相当简单的语 ...

  3. 【爬虫】python requests模拟登录知乎

    需求:模拟登录知乎,因为知乎首页需要登录才可以查看,所以想爬知乎上的内容首先需要登录,那么问题来了,怎么用python进行模拟登录以及会遇到哪些问题? 前期准备: 环境:ubuntu,python2. ...

  4. python3-使用requests模拟登录网易云音乐

    # -*- coding: utf-8 -*- from Crypto.Cipher import AES import base64 import random import codecs impo ...

  5. 【Python数据分析】Python模拟登录(一) requests.Session应用

    最近由于某些原因,需要用到Python模拟登录网站,但是以前对这块并不了解,而且目标网站的登录方法较为复杂, 所以一下卡在这里了,于是我决定从简单的模拟开始,逐渐深入地研究下这块. 注:本文仅为交流学 ...

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

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

  7. Python入门:模拟登录(二)或注册之requests处理带token请求

    转自http://blog.csdn.net/foryouslgme/article/details/51822209 首先说一下使用Python模拟登录或注册时,对于带token的页面怎么登录注册模 ...

  8. python爬虫学习,使用requests库来实现模拟登录4399小游戏网站。

    1.首先分析请求,打开4399网站. 右键检查元素或者F12打开开发者工具.然后找到network选项, 这里最好勾选perserve log 选项,用来保存请求日志.这时我们来先用我们的账号密码登陆 ...

  9. python学习,使用requests库来模拟登录github,post请求。

    这次我们要模拟登录的页面是 https://github.com/login 首先我们先尝试着登陆一遍分析一下请求, 打开开发者工具下的network选项, 可以很清楚的看到这个会话session,而 ...

随机推荐

  1. CSS盒子的浮动

    web前端学习笔记(CSS盒子的浮动) 在标准流中,一个块级元素在水平方向会自动伸展,直到包含它的元素的边界:而在竖直方向和兄弟元素依次排列,不能并排.使用“浮动”方式后,块级元素的表现就会有所不同. ...

  2. markdown实现

    博客园文章markdown实现   博客园也可以使用markdown写博客了~_~ 实现方法 在博客园管理-设置-页首Html代码中加入: <!-- Markdown --> <sc ...

  3. journaling保证意外故障下的数据完整性

    mongoDB研究笔记:journaling保证意外故障下的数据完整性   mongoDB的Journaling日志功能与常见的log日志是不一样的,mongoDB也有log日志,它只是简单记录了数据 ...

  4. Git - error: RPC failed; result=22, HTTP code = 401 fatal: The remote end hung up unexpectedly

    在用Git管理代码版本时,用git push命令提交代码,提示: 有以下几个可能性: Git 版本过低.GitCafe 推荐使用的 Git 版本是 >= 1.7. $ git --version ...

  5. markdownpad2注册及样式调整

    pro版密钥 邮箱: Soar360@live.com key: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6xhMNLGVpbP2 ...

  6. .net 配置文件 分析 EntityName 时出错

    今天用C#读写XML文档,总出现下面的错误: 分析 EntityName 时出错.行1,位置9. 出错地方的源程序为: //...... pathEle.InnerXml = reducedStr(v ...

  7. Apache错误:(20014)Internal error: Error retrieving pid file logs/httpd.pid

    今天在虚拟机上打开apache出现如下错误: [root@ShiGuang ~]# service httpd start (20014)Internal error: Error retrievin ...

  8. Python Tutorial - Parse JSON Objects with Python

    This tutorial is copied from youtube.com Here is the link: http://www.youtube.com/watch?v=RXqo3lC-JP ...

  9. linux 高精度定时器例子

    //author:DriverMonkey //phone:13410905075 //mail:bookworepeng@Hotmail.com //qq:196568501 #include &l ...

  10. 提高你的Java代码质量吧:不要让类型默默转换

    一.分析  在Java运算中的类型转换,是先运算在进行类型转换的.具体场景如下. 二.场景  在如下程序中: public class Client{ public static final int ...