s*******n 发帖数: 38 | 1 【 以下文字转载自 sysop 讨论区 】
发信人: samaritan (Good+Samaritan), 信区: sysop
标 题: 同主题转寄
发信站: BBS 未名空间站 (Thu Aug 18 19:32:26 2011, 美东)
这个bbs有不有同主题转寄的功能啊?有不有script作同主题转寄? | t****t 发帖数: 6806 | | N***m 发帖数: 4460 | 3 老大你真厉害,
【在 t****t 的大作中提到】 : 好奇问一下, 这个"有不有"是哪里的方言?
| s*******n 发帖数: 38 | 4 【 以下文字转载自 sysop 讨论区 】
发信人: samaritan (Good+Samaritan), 信区: sysop
标 题: 同主题转寄
发信站: BBS 未名空间站 (Thu Aug 18 19:32:26 2011, 美东)
这个bbs有不有同主题转寄的功能啊?有不有script作同主题转寄? | t****t 发帖数: 6806 | | N***m 发帖数: 4460 | 6 老大你真厉害,
【在 t****t 的大作中提到】 : 好奇问一下, 这个"有不有"是哪里的方言?
| s*******n 发帖数: 38 | 7 写了个同主题转寄的python script. 就是附件还不work. mitbbs的附件bs直接pass.
python新手。边学边编的。
----------------------------------------------
from urllib import request
from bs4 import BeautifulSoup, NavigableString
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from email.header import Header
#password=sys.argv[1]
password='*****'
address='http://www.mitbbs.com/article_t/Programming/17234582.html'
urlBase='http://www.mitbbs.com'
page = urllib.request.urlopen(address).read()
reNext = r'下页'
nextURL=re.findall(re.compile(reNext), page.decode('gbk', 'replace'))
reNext = r'(.*?)'
subject=re.findall(re.compile(reNext), page.decode('gbk','replace'))
subject="".join(subject);
page=page.decode('gbk','replace');
old_stdout=sys.stdout
myio=io.StringIO()
sys.stdout=myio
soup = BeautifulSoup(page, from_encoding='gbk')
def printText(tags):
for tag in tags:
if tag.__class__ == NavigableString:
print(tag),
else:
printText(tag)
printText(soup.findAll("p"))
while len(nextURL):
curURL = (urlBase+nextURL[0])
page = urllib.request.urlopen(curURL).read()
reNext = r'下页'
nextURL=re.findall(re.compile(reNext), page.decode('gbk'))
soup = BeautifulSoup(page, from_encoding='gbk')
print("")
print(r'==================NEXT PAGE=======================')
print("")
printText(soup.findAll("p"))
sys.stdout=old_stdout
message=myio.getvalue()
fromaddr='f******[email protected]'
toaddr='t****[email protected]'
username = 'u******[email protected]'
def mail(to, subject, text):
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
subjectHdr = Header(subject.encode('gbk'),'gb2312')
msg['Subject'] = subjectHdr
msg.attach(MIMEText(text.encode(), _charset='utf-8'))
#part = MIMEBase('application', 'octet-stream')
#part.set_payload(open(attach, 'rb').read())
#encoders.encode_base64(part)
#part.add_header('Content-Disposition','attachment; filename="%s"' % os.
path.basename(attach))
#msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(username, password)
mailServer.sendmail(username, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()
mail(toaddr, subject, message) |
|