python的http请求应用--每日签到
写点python吧,python其实是个很好用的工具,作为浇水语言,跟其他语言联系也很紧密,想用什么包直接import,导入ctypes调用底层函数库,导入web相关的包可以轻松写爬虫,今天我们写的跟web相关,程序员无所不能,我们创造个小人,这个小人每天定点给我们签到,(这个写出来后还得借助crontab稍后给大家献上C语言版的daemon签到,写C语言就没urllib包了,都是socket,或者说一切皆文件!)
俩文件bbs_login.py,bbs_sign.py,前者获取cookie,保存成本地文件后者借助cookie文件签到(就一post请求 )
#! /usr/bin/env python
# -*- coding:utf-8 -*- import cookielib
import urllib2
import urllib
import os url = 'http://xxx.xxx.com/asd' #一定是你登入提交的那个url ckjar = cookielib.MozillaCookieJar('cookie.txt')
#ckjar = cookielib.CookieJar()
data = {'password':'我是密码','username':'我是用户名'} postData = urllib.urlencode(data) req = urllib2.Request(url,postData)
#换成你的ua-我们这后台验证登入成功后会把ua,username作为因子DES加密后种到cookie里
req.add_header('User-Agent','Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.66 Safari/537.36') opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(ckjar))
urllib2.install_opener(opener) f =opener.open(req) htm = f.read()
print htm f.close() ckjar.save(ignore_discard=True, ignore_expires=True)
运行成功后会在当前目录的得到你的cookie.txt文件,然后我就拿这个cookie.txt文件认证了,其实这节可以当作一次XSS随笔:),这个cookie文件是Netscape/Mozilla cookie文件格式,ok,现在来看bbs_sign.py
#!/usr/bin/env python
#-*- coding=utf-8 -*-
#使用已有的cookie访问网站 import cookielib
import urllib2
import os ckjar = cookielib.MozillaCookieJar()
ckjar.load('/home/liet/code/python/study/web/cookie.txt') url = 'http://xxx.xxx.com/plugin.php?identifier=dps_sign&module=sign&operation=qiandao&infloat=1&inajax=1'
data = 'qdxq=kx&qdmode=1&todaysay=love+is+beautiful.so+beautiful&fastreply=1'
req = urllib2.Request(url, data) req.add_header('User-Agent','Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.66 Safari/537.36')
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(ckjar)) f = opener.open(req)
htm = f.read()
print htm
f.close()
ok,单独运行会看到签到成功的返回。。。。剩下我们把bbs_sign.py加入到crontab里,每天9点吧。。签到信息可以到sign.log里查
#每天签个到 by liet
* * * /usr/bin/python /root/liet/python/bbs_sign.py >> /root/liet/python/sign.log >&
python的http请求应用--每日签到的更多相关文章
- C语言socket编程--每日签到
前几天写了个python的每日签到,你运行还得借助crontab,很是不爽.....正好前几天看了个关于c编写daemon进程,加上自己那点可怜的socket知识,于是我们重操旧页,C语言版的每日签到 ...
- PHP+MYSQL+AJAX实现每日签到功能
一.web前端及ajax部分 文件index.html <html> <head> <meta http-equiv=Content-Type content=" ...
- Python中http请求方法库汇总
最近在使用python做接口测试,发现python中http请求方法有许多种,今天抽点时间把相关内容整理,分享给大家,具体内容如下所示: 一.python自带库----urllib2 python自带 ...
- python模拟Get请求保存网易歌曲的url
python模拟Get请求保存网易歌曲的url 作者:vpoet mail:vpoet_sir@163.com 日期:大约在夏季 #coding:utf-8 import requests impor ...
- python 发起HTTP请求
因为微信公众号群发需要调用高级群发接口,其中涉及到python发起HTTP请求,现在将相关实现操作记录如下: 首先,HTTP请求分为GET和POST,如下所示: 首先是发起get 请求: # -*- ...
- 随笔——python截取http请求报文响应头
随笔——python截取http请求报文响应头 标签: pythonhttp响应头 2014-05-29 09:32 2114人阅读 评论(0) 收藏 举报 分类: 随笔(7) 版权声明:本文为博 ...
- 基于【腾讯云函数】/【GitHub Actions】/【Docker】的每日签到脚本(支持多账号使用)
每日签到集合 基于[腾讯云函数]/[GitHub Actions]/[Docker]的每日签到脚本 支持多账号使用 特别声明: 本仓库发布的脚本及其中涉及的任何解锁和解密分析脚本,仅用于测试和学习研究 ...
- requests模块--python发送http请求
requests模块 在Python内置模块(urllib.urllib2.httplib)的基础上进行了高度的封装,从而使得Pythoner更好的进行http请求,使用Requests可以轻而易举的 ...
- python处理ajax请求
先要起一个服务 server.py,可以支持python的cgi脚本. #!coding:utf8 from BaseHTTPServer import HTTPServer from CGIHTTP ...
随机推荐
- Codeforces Round #218 (Div. 2) D. Vessels
D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- 002 The Variables In Csharp
在介绍本章之前,我们先看一下C#的编译过程,如下图所示: 图片摘自:http://www.developingthefuture.net/compilation-process-and-jit-com ...
- jmeter随笔(4)--中文url编码问题
最近在工作中,对jmeter实践的点滴的记录,这里分享交流,不一定正确,仅供参考和讨论,有想法的欢迎留言.谈论,手机上图片如果不清晰,请点击[阅读原文]查看. 技巧1:中文url编码问题 问题:我们抓 ...
- eclipse 拨打电话、拨号,发短信
1.拨打电话,拨号 //拨打电话Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(U ...
- Operator overloading
By defining other special methods, you can specify the behavior of operators on user-defined types. ...
- The init method
The init method is a special method that gets invoked when an object is instantiated. Its full name ...
- 8051学习笔记——AD
AD.C #include<reg52.h> #include <iic.h> #define PCF8591 0x90 //PCF8591 地址 sbit LS138A=P2 ...
- eclipse 弹出智能提示、代码自动换行
在eclipse 中编写java 程序时,为了快速查找变量或搜索方法调用,在智能窗口的帮助下,程序的编写速度会更快,但eclipse 默认下并不弹出智能窗口,这就需要自己进行配置,设置的步骤如下: 打 ...
- button的type属性
今天为看懂一段js代码纠结了很久,搞不明白数据是如何实现post,因为button没有规定属性,其次对submit事件没太搞明白.忽然想起默认属性这个概念,豁然开朗,啊~ 1.请始终为按钮规定 typ ...
- 学习练习 session练习
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...