注冊(cè)簡(jiǎn)書拔稳,首先得有個(gè)昵稱啊葛峻。但是好多名字都已經(jīng)被占用了,無奈巴比。
剛好今天在服務(wù)器上“逛街”的時(shí)候术奖,看到MySQL的安裝目錄下有這么一個(gè)文件 dictionary.txt,于是我有了一個(gè)大膽的想法礁遵。
現(xiàn)在昵稱有了,接下來就是驗(yàn)證下采记,看看能不能用佣耐,最后只需要在canbeused 類型的名字中找一個(gè)自己喜歡的就好啦。
在Chrome上抓包挺庞,看到有這么一個(gè)接口:
http://www.reibang.com/check_nickname
使用POST方式傳遞了一個(gè)nickname的參數(shù)晰赞。
好了,萬事俱備选侨,只欠Python了掖鱼,看看Python是怎么做的吧。
#!/usr/bin python
# coding: utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import requests
url = "http://www.reibang.com/check_nickname"
def getDictionaries(filepath):
with open(filepath, 'r') as f:
data = f.readlines()
f.close()
return data
def check(nickname):
"""
不可用:{"error":[{"message":"昵稱 已經(jīng)被使用","code":888}]}
可用: 返回內(nèi)容為空
:param nickname:
:return:
"""
payload = {
"nickname": nickname
}
headers = {
"Host": "www.reibang.com",
"Origin": "http://www.reibang.com",
"Referer": "http://www.reibang.com/sign_up",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
}
response = requests.post(url=url, data=payload, headers=headers)
result = response.text
print result
return 0 if result!="" else 1
def main():
cannotuse = []
canbeuse = []
filepath = "/tmp/dictionary.txt"
nicknames = getDictionaries(filepath=filepath)
for nickname in nicknames:
print "檢測(cè) {} ...".format(nickname)
result = check(nickname=nickname)
if result == 1:
cannotuse.append(nickname)
else:
canbeuse.append(nickname)
return (cannotuse, canbeuse)
if __name__ == '__main__':
cannotbeuse, canbeuse = main()
with open("/tmp/canbeuse.txt", "w") as canfile:
canfile.writelines(canbeuse)
canfile.close()
with open("/tmp/cannotbeuse.txt", "w") as cannotfile:
cannotfile.writelines(cannotbeuse)
cannotfile.close()
print "Over!"
然后援制,我就有了一個(gè)名字: DLUT戏挡。這是在簡(jiǎn)書寫的第一篇文章,接下來我會(huì)慢慢的把之前在CSDN的文章搬過來晨仑,希望能在簡(jiǎn)書這個(gè)平臺(tái)上褐墅,更上一層樓!