Обучение/Помощь новичкам | Проблема не могу понять
html
import socket # create socket s = socket.socket() # bind socket to a address and port s.bind(('localhost', 12345)) # put the socket into listening mode s.listen(5) print('Server listening...') # forever loop to keep server running while True: # establish connection with client client, addr = s.accept() print(f'Got connection from {addr}') # receive the file name file_name = client.recv(1024).decode() try: # open the file for reading in binary with open(file_name, 'rb') as file: # read the file in chunks while True: chunk = file.read(1024) if not chunk: break # send the chunk to the client client.sendall(chunk) print(f'File {file_name} sent successfully') except FileNotFoundError: # if file not found, send appropriate message client.sendall(b'File not found') print(f'File {file_name} not found') # close the client connection client.close() html
from selenium import webdriver import requests as rq import os from bs4 import BeautifulSoup import time # path= E:\web scraping\chromedriver_win32\chromedriver.exe path = input("Enter Path : ") url = input("Enter URL : ") output = "output" def get_url(path, url): driver = webdriver.Chrome(executable_path=r"{}".format(path)) driver.get(url) print("loading.....") res = driver.execute_script("return document.documentElement.outerHTML") return res def get_img_links(res): soup = BeautifulSoup(res, "lxml") imglinks = soup.find_all("img", src=True) return imglinks def download_img(img_link, index): try: extensions = [".jpeg", ".jpg", ".png", ".gif"] extension = ".jpg" for exe in extensions: if img_link.find(exe) > 0: extension = exe break img_data = rq.get(img_link).content with open(output + "\\" + str(index + 1) + extension, "wb+") as f: f.write(img_data) f.close() except Exception: pass result = get_url(path, url) time.sleep(60) img_links = get_img_links(result) if not os.path.isdir(output): os.mkdir(output) for index, img_link in enumerate(img_links): img_link = img_link["src"] print("Downloading...") if img_link: download_img(img_link, index) print("Download Complete!!") html
import smtplib from email.mime.text import MIMEText # Set the SMTP server and login credentials smtp_server = "smtp.gmail.com" smtp_port = 587 username = "your@email.com" password = "yourpassword" # Set the email parameters recipient = "recipient@email.com" subject = "Test email from Python" body = "This is a test email sent from Python." # Create the email message msg = MIMEText(body) msg["Subject"] = subject msg["To"] = recipient msg["From"] = username # Send the email server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() server.login(username, password) server.send_message(msg) server.quit()
Не грузит файлы что делать?
html
import PyPDF2 # open two pdfs pdf1File = open('example.pdf', 'rb') pdf2File = open('example2.pdf', 'rb') # read first pdf pdf1Reader = PyPDF2.PdfFileReader(pdf1File) # read second pdf pdf2Reader = PyPDF2.PdfFileReader(pdf2File) # for writing in new pdf file pdfWriter = PyPDF2.PdfFileWriter() for pageNum in range(pdf1Reader.numPages): pageObj = pdf1Reader.getPage(pageNum) pdfWriter.addPage(pageObj) for pageNum in range(pdf2Reader.numPages): pageObj = pdf2Reader.getPage(pageNum) pdfWriter.addPage(pageObj) # create new pdf 'example3.pdf' pdfOutputFile = open('example3.pdf', 'wb') pdfWriter.write(pdfOutputFile) pdfOutputFile.close() pdf1File.close() pdf2File.close()