-
Notifications
You must be signed in to change notification settings - Fork 0
/
收取Archdaily订阅邮件.py
30 lines (23 loc) · 794 Bytes
/
收取Archdaily订阅邮件.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import imapclient
imapObj = imapclient.IMAPClient('mail.cortt.me', ssl=False)
imapObj.login('[email protected]','Rss@123456')
imapObj.select_folder('INBOX',readonly=True)
UIDs = imapObj.search('UNSEEN')
print(UIDs)
rawMessage = imapObj.fetch(UIDs,['BODY[]'])
#import pprint
#pprint.pprint(rawMessage)
import imaplib
imaplib._MAXLINE = 1000000
import pyzmail
message = pyzmail.PyzMessage.factory(rawMessage[3][b'BODY[]'])
from bs4 import BeautifulSoup
# 获取订阅邮件正文并解析为bs4对象/
if message.html_part != None:
html_str = message.html_part.get_payload().decode(message.html_part.charset)
bsObj = BeautifulSoup(html_str, 'lxml')
# 提取项目链接URL
url_ori = bsObj.find_all('tbody')
print(url_ori[-2])
# 利用正则表达式提取项目url
#import re