apache 2.4.7实现https服务

创建cert文件夹

mkdir /etc/apache2/cert

阅读全文

Python 发送QQ邮箱邮件代码

QQ邮箱使用SSL的方式去登录方法,所以和普通的发送邮箱代码不太一样。

s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(_user, _pwd)

阅读全文

Python 发送Email模块

#encoding=utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
def Email_163(receiver,subject,text,model):
Sender = "xxx" # 发件人Email地址
AuthorizationCode = 'xxxx' # 授权码,163邮箱开启SMTP服务时授权第三方登陆邮箱的授权码
smtp_server = 'xx' # SMTP服务器地址
# HTML内容
# msg = MIMEText('<html><body><h1>Hello</h1>' +
# '<p>send by <a href="http://www.python.org">Python</a>...</p>' +
# '</body></html>', 'html', 'utf-8')
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = Header(subject, 'utf-8') # 邮件主题
msgRoot['From'] = formataddr(['xx', Sender]) # 发件人,显示在收件人界面上
msgRoot['To'] = formataddr(['', receiver]) # 收件人
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgAlternative.attach(MIMEText(text, model, 'utf-8'))
fp = open('test.jpg', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage)
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(smtp_server, 25) # 25 为 SMTP 端口号
smtpObj.login(Sender, AuthorizationCode) # 登陆邮箱
smtpObj.sendmail(Sender, receiver, msgRoot.as_string()) # 发送邮件
smtpObj.quit() # 推出
print u"发送成果"
except smtplib.SMTPException,e:
print u"发送失败"
print e
Email_163("xxx",'你好',''' <html>
<head>测试一下</head>
<body>
你们好啊<br>
<br><img src="cid:image1"></br>
</p>
</body>
</html> ''','html')

阅读全文

PHP_MD5加密

md5($str)

使用md5(string,raw)函数即可完成md5加密

阅读全文

链家房屋爬虫

使用xlwt库将爬取内容写入excel

#coding=UTF-8
import urllib2
from bs4 import BeautifulSoup
import sys
import xlwt
page=1
num=0
book=xlwt.Workbook(encoding="utf-8",style_compression=0)
sheet=book.add_sheet('test',cell_overwrite_ok=True)
while page<100:
pages = str(page)
url = "http://ty.fangjia.com/zufang/--e-" + pages + "#pagelist"
reload(sys)
sys.setdefaultencoding('utf-8')
html = urllib2.urlopen(url)
soup = BeautifulSoup(html, "html.parser")
house = soup.find("div", class_="house")
for home in house.find_all("li", {"name": "__page_click_area"}):
for title in home.find_all("span", class_="tit"):
for text in title.stripped_strings:
sheet.write(num+1, 0, text)
for address in home.find_all("span", class_="address"):
i=1
for text in address.stripped_strings:
sheet.write(num + 1, i, text)
i=i+1
for attribute in home.find_all("span", class_="attribute"):
for text in attribute.stripped_strings:
sheet.write(num + 1, 3, text)
for price in home.find_all("span", class_="xq_aprice xq_esf_width"):
for text in price.em.stripped_strings:
sheet.write(num + 1, 4, text+ "万")
num=num+1
print str(page) + "页插入完成"
book.save('/Users/dubo/Desktop/typrice2.xls')
page = page + 1
print "总计"+str(num)+"套房屋"

阅读全文

豆瓣读书Top250

#coding=UTF-8
import urllib2
from bs4 import BeautifulSoup
# https://book.douban.com/top250?start=
time=0
sum=25
while time<=225:
times=str(time)
url="https://book.douban.com/top250?start="+times
req = urllib2.urlopen(url)
content = req.read()
soup=BeautifulSoup(content,"html.parser")
print "----------page=" + str(sum/25) + "-----------"
for link in soup.find_all('div',{"class":"pl2"}):
for text in link.find_all("a"):
for none in text.stripped_strings:
print none
sum=sum+1
time=time+25
print sum-25

阅读全文

Swift GET&POST请求 网络缓存的简单处理

参考该CSDN
CNBLOG

阅读全文

Swift同步请求获取网络数据demo

let APIURL="http://www.mrdubo.com/api/api.php"
let url=URL(string: APIURL)
//创建请求对象
let urlRequest:NSURLRequest = NSURLRequest(url: url!)
let ur:NSURLRequest=NSURLRequest(url: url!, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalCacheData , timeoutInterval: 5)
//响应对象
var response:URLResponse?
do{
//发送请求
let jsonData:NSData? = try NSURLConnection.sendSynchronousRequest(urlRequest as URLRequest,returning: &response) as NSData?
if jsonData==nil {
print("error")
exit(-1)
}
}catch let error as NSError{
//打印错误消息
var alterView = UIAlertController()
alterView.title="Network"
alterView.message="Network not allowed"
var cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel, handler: nil)
alterView.addAction(cancelAction)
self.present(alterView,animated: true, completion: nil)
}
}

阅读全文

NSURLRequest各种缓存方式讲解

1.NSURLRequestUseProtocolCachePolicy NSURLRequest

默认的cache policy,使用Protocol协议定义。
2.NSURLRequestReloadIgnoringCacheData

忽略缓存直接从原始地址下载。
3.NSURLRequestReturnCacheDataDontLoad

阅读全文

Swift中三元运算符的低级错误

var str = a>b ?"123" : "1234"

阅读全文