In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Python how to automatically get the latest notification of the target site, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
1. Establish a notification database
The purpose of this step is to crawl and store the data of the notifications that have been published by the target website, so as to establish a local database corresponding to the content of the target website.
Considering that the data in the database will be the only way to identify and obtain a new notification, the established database will store the title, release date, and access link of each notification.
The modules used in the first step are urllib, BeautifulSoup and sqlite3 modules. Among them, crawl the html data of the target web page through the urllib module; analyze the web page data and crawl the web page content through the BeautifulSoup module; establish the existing notification database of the target website through the sqlite3 module.
two。 Establish a mail delivery system
The purpose of this step is to use the Python standard library module smtplib to access the network and create a function to send e-mail.
Since most of our computers do not set up our own mail servers, we need to use third-party servers to simulate mail delivery.
Commonly used are Google mail system, NetEase mail system and QQ mail system. For example, the SMTP server and port number of QQ mail system are smtp.qq.com and 465 respectively.
The main code for this step is shown below.
In this example, the email module in the Python standard library is used to format the e-mail information, including the subject and sender of the message, the recipient's mailbox nickname, and the content of the message.
3. Analyze the notification of the target website
The first two steps have completed the establishment of the existing notification database and e-mail sending system of the target website, and the work to be completed in the third step is mainly composed of two parts.
First, use the urllib and BeautifulSoup modules used in the first step to parse the content data of the target website, and compare it with the database established earlier.
Second, if a new notification is detected on the target website, the new notification data is inserted into the database, and then a prompt email is sent.
The main code for this step is shown below.
In this example, only the latest notification is selected and the email prompt is sent, and the specific email information can be set by yourself.
4. Develop planned tasks
In the first three steps, you have completed a script that uses Python to get the latest notifications from the target site and send prompt emails.
In this step, you will use the DOS command framework and task scheduler that comes with Windows to automatically run the Python script every hour for the purpose of automatically updating notifications.
First, you need to write a cmd command file to facilitate the execution of Python scripts in the DOS framework.
The main code is shown as follows:
@ echo off # turn off echo cd C:\ demo # find the path to the Python script file python Python.py # execute the Python script file
Finally, use the Task Scheduler to create a task that can be set to run the cmd command file automatically every other hour.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.