注册简书,首先得有个昵称啊。但是好多名字都已经被占用了,无奈。
刚好今天在服务器上“逛街”的时候,看到MySQL的安装目录下有这么一个文件 dictionary.txt,于是我有了一个大胆的想法。
现在昵称有了,接下来就是验证下,看看能不能用,最后只需要在canbeused 类型的名字中找一个自己喜欢的就好啦。
在Chrome上抓包,看到有这么一个接口:
https://www.jianshu.com/check_nickname
使用POST方式传递了一个nickname的参数。
好了,万事俱备,只欠Python了,看看Python是怎么做的吧。
#!/usr/bin python
# coding: utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import requests
url = "https://www.jianshu.com/check_nickname"
def getDictionaries(filepath):
with open(filepath, 'r') as f:
data = f.readlines()
f.close()
return data
def check(nickname):
"""
不可用:{"error":[{"message":"昵称 已经被使用","code":888}]}
可用: 返回内容为空
:param nickname:
:return:
"""
payload = {
"nickname": nickname
}
headers = {
"Host": "www.jianshu.com",
"Origin": "https://www.jianshu.com",
"Referer": "https://www.jianshu.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 "检测 {} ...".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!"
然后,我就有了一个名字: DLUT。这是在简书写的第一篇文章,接下来我会慢慢的把之前在CSDN的文章搬过来,希望能在简书这个平台上,更上一层楼!