python实现批量注册网站用户的示例

yipeiwu_com6年前Python基础

如下所示:

# -*- coding:utf-8 -*-
 
import random,urllib,urllib2
import re,time
x=input("请输入需要注册的数量:")
# x=raw_input() #转换成字符串的
 
def h(i,y):
	
	user=str(random.randrange(10000000,99999999))
 
	QQ=str(random.randrange(10001,999999999999))
 
	pwd=str(random.randrange(100000,99999999))
 
 
	url="http://www.qb5.com/register.php?do=submit"
 
 
	data={"username":user,
	"password":pwd,
	"repassword":pwd,
	"email":QQ+"@qq.com",
	"qq":QQ,
	"sex":"0",
	"action":"newuser",
	"submit":""}
 
	data=urllib.urlencode(data)
 
	req=urllib2.Request(url,data=data)
	print data
	# html=urllib2.urlopen(req).read()
	# print(html)
	html=urllib2.urlopen(req).read().decode('gbk')
 
	# print(type(html))
	reg=u'您已成功注册成为本站用户'
	reg=re.compile(reg)
	r=re.findall(reg,html)
	if r!=[]:
		print("注册成功,账号为%s,密码为%s,目前注册到第%s,还剩%s个"%(user,pwd,i+1,y-i-1))
		f=open("c:\user.txt","a")
		f.write("%s----%s----%s@qq.com----%s\n" %(user,pwd,QQ,QQ))
		# f.write("qq----123456")
		f.close()
 
for i in range(x):
	h(i,x)
	# 延时
	time.sleep(2)

以上这篇python实现批量注册网站用户的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中那些 Pythonic的写法详解

前言 Martin(Bob大叔)曾在《代码整洁之道》一书打趣地说:当你的代码在做 Code Review 时,审查者要是愤怒地吼道: “What the fuck is this shi...

Python编程语言的35个与众不同之处(语言特征和使用技巧)

一、Python介绍   从我开始学习Python时我就决定维护一个经常使用的“窍门”列表。不论何时当我看到一段让我觉得“酷,这样也行!”的代码时(在一个例子中、在StackOverfl...

nohup后台启动Python脚本,log不刷新的解决方法

问题: =》nohup python3 xxxx.py &后台启动脚本 tail -100f nohup.out    -------->  &nbs...

Python使用pymysql从MySQL数据库中读出数据的方法

python3.x已经不支持mysqldb了,支持的是pymysql 使用pandas读取MySQL数据时,使用sqlalchemy,出现No module named ‘MySQLdb...

Windows 安装 Anaconda3+PyCharm的方法步骤

Windows 安装 Anaconda3+PyCharm的方法步骤

由于本人使用的是windows 10 操作系统,所以介绍在 windows 10 系统中安装 Anaconda3 的过程。 下载 Anaconda 官网下载地址:https://www....