You are on page 1of 4

CODE 1:

import requests
from bs4 import Beau fulSoup

def scrape_quotes():
# Send a GET request to the website
url = 'h p://quotes.toscrape.com'
response = requests.get(url)

# Check if the request was successful (status code 200)


if response.status_code == 200:
# Parse the HTML content of the page
soup = Beau fulSoup(response.text, 'html.parser')

# Extract quotes and authors


quotes = []
for quote in soup.find_all('span', class_='text'):
quotes.append(quote.get_text())

authors = []
for author in soup.find_all('small', class_='author'):
authors.append(author.get_text())

# Print the scraped data


for i in range(len(quotes)):
print(f"Quote: {quotes[i]}")
print(f"Author: {authors[i]}")
print()
else:
print(f"Failed to retrieve the page. Status code: {response.status_code}")

if __name__ == "__main__":
scrape_quotes()
CODE 4:

Server Code:

import socket

# create a socket object

s = socket.socket()

print("Socket successfully created")

# reserve a port on your computer

port = 40674

# bind the socket to the specified port

s.bind(('', port))

print("Socket binded to %s" % (port))

# put the socket into listening mode

s.listen(5)

print("Socket is listening")

# a forever loop un l we interrupt it or an error occurs

while True:

# Establish connec on with client.

c, addr = s.accept()

print('Got connec on from', addr)

# send a thank you message to the client.

c.send(b'Thank you for connec ng')

# Close the connec on with the client

c.close()

Client Code:

import socket
# create a socket object

s = socket.socket()

# reserve a port on your computer

port = 40674

# connect to the server on local computer

s.connect(('127.0.0.1', port))

# receive data from the server

print(s.recv(1024))

# close the connec on

s.close()
CODE 7:

import cv2

# Ini alize the camera

cap = cv2.VideoCapture(0)

# Load the pre-trained face classifier

face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

# Counter for naming images

count = 0

while True:

ret, frame = cap.read()

if not ret:

break

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

faces = face_cascade.detectMul Scale(gray, 1.3, 5)

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

# Draw a rectangle around the face

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

# Capture and save the face in the images folder

cv2.imwrite(f'images/face_{count}.jpg', frame[y:y+h, x:x+w])

count += 1

cv2.imshow('Capturing Faces', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):

break

cap.release()

cv2.destroyAllWindows()

You might also like