功能:将QQ阅读的书记下载,并回传到kindle上
使用模块:
- selenium
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time
from selenium.webdriver.common.action_chains import ActionChains
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email import Encoders, Utils
import smtplib
from email.Header import Header
- getopt
import getopt, sys
reload(sys)
sys.setdefaultencoding('utf-8')
注意事项:
- selenium定位以及切换frame(iframe)
frame标签有frameset、frame、iframe三种,frameset跟其他普通标签没有区别,不会影响到正常的定位,而frame与iframe对selenium定位而言是一样的,selenium有一组方法对frame进行操作。
所以只要善用以下三个方法,遇到frame分分钟搞定:
driver.switch_to.frame(reference) #切入frame,使用id,或者name属性
driver.switch_to.parent_frame()#切回上一级frame
driver.switch_to.default_content()#切回主页面
- 命令行传入参数
try:
opts, args = getopt.getopt(sys.argv[1:], "f:u:", [])
except getopt.GetoptError:
# print help information and exit:
pass
for name, value in opts:
if name in ("-u"):
url1 = value
if name in ("-f"):
filename1 = value
print url1,filename1
- 发邮件
filename = filename + ".txt"
server = 'smtp.163.com'
username = "rufus_tang"
password = 'y880228'
from_mail = 'rufus_tang@163.com'
to_mail = '15825279415_e6b0cb@kindle.cn'
smtp = smtplib.SMTP()
smtp.connect(server)
smtp.login(username, password)
msg = MIMEMultipart()
msg['to'] = to_mail
msg['from'] = from_mail
msg['Subject'] = "Convert"
msg['Date'] = Utils.formatdate(localtime=1)
content = open(filename, 'rb').read()
att = MIMEText(content, 'base64', 'utf-8')
att['Content-Type'] = 'application/octet-stream'
att["Content-Disposition"] = "attachment;filename=\"%s\"" % Header(filename, 'gb2312')
msg.attach(att)
smtp.sendmail(msg['from'], msg['to'], msg.as_string())
smtp.quit()
网友评论