In the original release https://blog.csdn.net/qq_21484935/article/details/103461778
Ideas: request url and parse the content of the novel, find a span of time with the update. Then configure the mailbox content as sent.
I chose NetEase 126 mailbox, the official website login account, settings, open the "POP3 / SMTP / IMAP", ( here need the phone to send a verification message
After successful as shown:
port information is as follows:
the next steps very simple, python's SMTP operation (please do not look at Baidu
ado, directly on the code
import logging
import smtplib
from email.mime.text import MIMEText
import requests
from bs4 import BeautifulSoup
server = 'smtp.126.com'
sender = '[email protected]' #发送邮箱
mailpass = 'xxxxx' #客户端授权码
receivers =['[email protected]'] #接收邮箱
def getUrl(url , header):
req = requests.get(url , header)
bs = BeautifulSoup(req.text , 'html5lib')
time = bs.select('body > div.wrap.cf > div.main > div.chapterlist > div.chapterlist_box > div > div > span')[0]
return time.string #返回更新时间
def send(text):
snd_msg = MIMEText(text,'plain' ,'utf-8')
snd_msg['From'] = "{}".format(sender)
snd_msg['To'] = ",".join(receivers)
snd_msg['Subject'] = '<鬼刀>更新信息'
try:
smtp = smtplib.SMTP_SSL(server, 465) #ssl协议 端口465
smtp.login(sender , mailpass) #发送者邮箱 客户端授权码
smtp.sendmail(sender , receivers , snd_msg.as_string())
print('发送成功!')
except smtplib.SMTPException:
logging.error('failed to send email!')
def init(url):
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
}
try:
text = getUrl(url , header)
return text
except Exception as e:
print(e)
if __name__ == "__main__":
url = 'http://www.u17.com/comic/68471.html'
text = init(url)
send(text)
Illustrate subsequent steps is not excessive. You can set what time to apply, mount to the server, from time to time update does not detect it, and then sent to the mailbox. Zizi is not beautiful. (Have not seen this cartoon, you see more small partners can Tucao about Yo