尝试在这里创建一个脚本,登录www.marapets.com,然后执行一些操作(在本例中,刷新以发生随机事件,然后激活它)。然而,他们使用两步身份验证,我不知道如何使用python以这种方式登录,你们中有人知道如何使用吗
以下脚本应在1stage登录网站上完全运行
如果你们中的一个人想要测试一个脚本,在上面的帐户的登录详细信息如下
username=“stackoverflow1” password=“qwerty123456”
我的剧本如下
import sys,time,urllib,urllib2,cookielib,re,random,os
from datetime import datetime
caj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(caj))
opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0'),]
### User Details
username = "stackoverflow1"
password = "qwerty123456"
### CONSTANTS (Don't Touch)
LINK = "http://www.marapets.com/explore.php\?collect="
### COMPUTERS VARIABLES (Don't Touch)
regex = "<a href='"+LINK+"(.*?)'>"
### Functions
def GetUsernameFromID():
url = "http://www.marapets.com/login.php"
values = {'username' : username}
strHTML = web(url,values)
idMatch = re.compile("<input type='hidden' name='username' value='(.*?)'>")
try:
UserID = idMatch.findall(strHTML)
return UserID[0]
except:
print "User does not exist.3124"
def Login():
UserID = GetUsernameFromID()
loginData = {'id' : UserID, 'password' : password}
url = "http://www.marapets.com/dologin.php"
if web(url,loginData) == "Bad Username":
print "User does not exist.21"
time.sleep(1)
def Regex(pattern,string):
pattern = re.compile(pattern)
try:
return pattern.findall(string)
except:
return None
def web(url,values="none",update=0):
try:
global NewThread
if values == "none":
## USE GET
text = opener.open(url,timeout = 5).read()
if text.find('Your account has been banned') > -1:
print "This account is banned...."
return
return text
else:
## USE POST
data = urllib.urlencode(values)
text = opener.open(url,data,timeout = 5).read()
if text.find('Your account has been banned') > -1:
print "This account is banned...."
SetStatus("This account is banned.")
return
return text
except ArithmeticError:
print ""
except Exception,e:
print e
print "Check Internet Connection/Proxy " + url
Login()
print "logged in"
i = 0
cake = 0
while 1:
os.system("cls")
print "Loop #",i+1
print "Cakes:",cake
webpage = web(random.choice(["http://www.marapets.com/atm.php","http://www.marapets.com/explore.php","http://www.marapets.com/news.php","http://www.marapets.com/giant.php"]))
#print webpage
try:
link = Regex(regex,webpage)[0]
HTML = web(LINK.replace("\\","")+link)
print link
if HTML.find("You opened") > -1:
cake = cake + 1
except Exception,e:
print "No cake here"
i = i + 1
目前没有回答
相关问题 更多 >
编程相关推荐