-
Notifications
You must be signed in to change notification settings - Fork 1
/
castic.py
95 lines (69 loc) · 2.03 KB
/
castic.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# coding: UTF-8
# @Date : 2015-09-16 15:46:47
# @Author : LinPan
# @Email : [email protected]
# @Version : 1.0
'''
Problem:
Solution: lxml,css selector,Python:
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
'''
import requests,sqlite3
import smtplib
import sys
from lxml import html
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
link='http://www.casitc.com/casitc/?cat=6'
def getinfo(link):
page=requests.get(link)
tree = html.fromstring(page.text)
linktitle=tree.xpath('//li[contains(@style,"margin:20px")]/a/text()')
linkhref=tree.xpath('//li[contains(@style,"margin:20px")]/a/@href')
n=dict(zip(linkhref,linktitle))
return n
#避免多次插入,否则出错了!
def Sendemail(text):
port=25
mailto=['[email protected]']
mail_host='smtp.163.com'
mail_user='[email protected]'
mail_pass='s1108057'
mail_fix='163.com'
receiver='[email protected]'
msg = MIMEText(text,_subtype='html',_charset='gb2312')
msg['subject']='www.casitc.com'
msg['from']=mail_user
msg['to']=receiver
sen=smtplib.SMTP(mail_host,port)
sen.login(mail_user,mail_pass)
sen.sendmail(mail_user,receiver, msg.as_string())
sen.close()
if __name__=='__main__':
s=''
for index,k,v in enumerate(getinfo(link).items()):
#print k,v
boby='<br><a href='+k +'> '+ v +'</a></br>'
s += boby
Sendemail(s)
print '你的邮件已发生完毕!请查收'
#def get_con():
conn = sqlite3.connect("F:/est.db")
cu=conn.cursor()
#cu.execute("create table aaa(id INTEGER PRIMARY KEY AUTOINCREMENT,title varchar(40) UNIQUE,link varchar(20), updatetime TEXT)")
link='http://www.casitc.com/casitc/?cat=6'
c=getinfo(link)
save_sql = 'INSERT INTO aaa values (?, ?, ?, ?)'
#for i in xrange(len(c)):
# link=c.items()[i][0]
# title=c.items()[i][1]
# date=title.split(' ')[-1]
#cu.execute(save_sql, (None,title,link,date))
# conn.commit()
#cu.execute("select * from aaa")
#print cu.fetchone().encode('utf-8')
# V=get_con()