You can view the full code here: https://pastebin.com/ND8EYTxA
Install Python
I will take the site as an example https://www.okazii.ro/
Also as an example of a product on this website, I will look for the book: "Studiul desenului, culorii, compozitiei si expresiei in arta eclesiala"
The Python code will have to notify me by email when this book returns to stock, with a price of less than 90 RON.
Mention: If you want this code to run continuously in the background, you will need to change the file extension from .py in .pyw
Before running the script you need to do the following:
From the CMD (command prompt) console, run the command:pip install pythonw
To start the program run the following command in CMD (in the folder where the file is located):
pythonw okazii.pyw
Now the process will run continuously in the background. To stop the process, you must run the command:
TASKKILL /F /IM pythonw.exe
CAREFUL ! ! ! All commands are run from the command line in the folder where the file is located.
If you want to simply run the file with python okazii.pyw, you can do that too, but you should always keep the console open. You can stop the execution with ctrl + C from Command Prompt (CMD)
Do not use GMAIL for default email adress !
#------------------------------------------------------------------------------- # Author: Fantanaru Neculai # # Created: 16/03/2022 # Copyright: (c) Fantanaru Neculai 2022 #------------------------------------------------------------------------------- from bs4 import BeautifulSoup as bs import pandas as pd pd.set_option('display.max_colwidth', 500) import time import requests import random import re page = requests.get("https://www.okazii.ro/") soup = bs(page.content) # Studiul desenului, culorii, compozitiei si expresiei in arta eclesiala result = requests.get("https://www.okazii.ro/cautare/studiul+desenului%2C+culorii%2C+compozitiei+si+expresiei+in+arta+eclesiala.html") # preluam text dintre <!-- END SPECIALE IN LISTA--> si <!-- RECENT INTRODUSE --> produse_sectiune_pattern = re.compile('<!-- END SPECIALE IN LISTA-->([\s\S]*?)<div id=\'div-gpt-ad-15\'>') produse_sectiune = re.findall(produse_sectiune_pattern, result.text) produse_sectiune = produse_sectiune[0] preturi_pattern = re.compile('<span class=\"prSup\"><span>(.*?)</span><span class=\"seo-price-indent\">') preturi = re.findall(preturi_pattern, produse_sectiune) print(preturi) count = 0 for pret in preturi: if int(pret) < 90: # puneti <= daca vreti ca pretul sa fie si egal cu 90 RON count += 1 print("Am gasit {} oferte cu pretul sub 90 lei.".format(count)) # soup_cautare = bs(result.text, 'html.parser') # print(soup_cautare) #items = soup_cautare.find_all(class_ = 'listing-product ') #print(items) # Trimitere email import sys import smtplib from_addr = 'YOUR EMAIL ADRESS' to_addrs = ['YOUR EMAIL ADRESS'] msg = """From: Sender To: Recipient Subject: Okazii Am gasit 1 oferte cu pretul sub 90 lei. """ try: s = smtplib.SMTP('mail.neculaifantanaru.com', 26) # put here your own SMTP PORT and hosting email s.login('YOUR EMAIL ADRESS', 'PASSWORD') # do not use GMAIL !! s.sendmail(from_addr, to_addrs, msg) s.quit() except smtplib.SMTPException: print("Error: ", sys.exc_info()[0])
That's all folks.
If you like my code, then make me a favor: translate your website into Romanian, "ro".
Also, see this VERSION 2 or VERSION 3 or VERSION 4 or VERSION 5 or VERSION 6 or VERSION 7