之前写的一些有意思的函数,因为每次自己再敲一遍又很麻烦,故写好了可以直接复制就可以用了
1.跑跑弱口令字典
之前一个课上用的,字典是从github上找的:https://github.com/fuzz-security/SuperWordlist
1 2 3 4 5 6 7
| flag = False with open("MidPwds.txt", "r",encoding='utf-8') as f: for line in f.readlines(): line = line.strip('\n') if line == pwd: flag = True break
|
2.发邮件函数
自己封装了个发邮件函数,写一些自动化任务可能会用到
需要的参数:
需要用到的库:
- smtplib
- email.mime.text
- email.utils
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import smtplib from email.mime.text import MIMEText from email.utils import formataddr
def email(text,email): my_sender = '你的邮箱' my_pass = "邮箱TOKEN" msg=MIMEText(text,'plain','utf-8') msg['Subject']="这是一个主题" msg['From']=formataddr(["我是发件人",my_sender]) msg['To']=formataddr(["我是收件人",email]) server=smtplib.SMTP("smtp.163.com", 25) server.login(my_sender, my_pass) server.sendmail(my_sender,email,msg.as_string()) server.quit()
|
3.获取B站视频播放量/专栏阅读数和粉丝
需要一个参数UID
还有需要requests和json库
返回两个参数:
- fans_data : 粉丝数
- views : 总播放量
- article_views : 专栏阅读量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import requests,json
def bilibili(UID): url1 = 'https://api.bilibili.com/x/space/arc/search?mid='+str(UID)+'&ps=30&tid=0&pn=1&keyword=&order=pubdate&jsonp=jsonp' url2 = 'https://api.bilibili.com/x/relation/stat?vmid='+str(UID)+'&jsonp=jsonp' url3 = "https://api.bilibili.com/x/space/article?mid="+str(UID)+"&pn=1&ps=12&sort=view&jsonp=jsonp" try: views_data = json.loads(requests.get(url1).text)['data']['list']['vlist'] articles_data = json.loads(requests.get(url3).text)["data"]["articles"] fans_data = json.loads(requests.get(url2).text)['data']['follower'] except: return "数据获取失败" views=0 for i in views_data: views+=i['play']
article_views = 0 for i in articles_data: article_views+=i["stats"]["view"] return fans_data,views,article_views
|
效果图:
4.获取宿舍电量