怎么样通过Python实现博客日志自动提交程序?
import urllib,urllib2,cookielib
import re
BOKEE_HOST='.bokee.com'
class Bokee:
def __init__(self):
self.UserName=''
self.Password=''
self.cookie=cookielib.CookieJar()
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
urllib2.install_opener(self.opener)
def login(self,username,password):
self.bokeeFile="bokee.xml"
self.UserName=username
self.BlogPath="http://" self.UserName BOKEE_HOST
_str=urllib.urlencode({'username':username,'password':password})
_response=urllib2.urlopen('http://reg.bokee.com/account/LoginCtrl.b',_str)
_d=_response.read()
if (re.search('bokie', _d)):
return True
else:
return False
def PostIt(self,_title,_content):
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
urllib2.install_opener(self.opener)
_req=urllib2.Request(url=self.BlogPath '/control/doPostDiary.b')
_req.add_header('Content-Type','text/xml;charset=GBK')
_data=open('bokee.xml','r').read()
_data=_data.replace('$#content#$',_content)
_data=_data.replace('$#title#$,_title)
_req.add_data(_data)
_r=urllib2.urlopen(_req)
#_d=_r.read()
if (re.search(r'SUCCESS',_r.read())):
return True
else:
return False
<parameters>
<parameter>
<parameter-name>diary.diaryContent</parameter-name>
<parameter-value><![CDATA[$#content#$]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.diaryTitle</parameter-name>
<parameter-value><![CDATA[$#title#$]]></parameter-value>
</parameter>
<parameter>
<parameter-name>categoryName</parameter-name>
<parameter-value><![CDATA[]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.tag</parameter-name>
<parameter-value><![CDATA[]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.trackbackURLToSend</parameter-name>
<parameter-value><![CDATA[]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.remarkAble</parameter-name>
<parameter-value><![CDATA[1]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.postType</parameter-name>
<parameter-value><![CDATA[1]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.summary</parameter-name>
<parameter-value><![CDATA[]]></parameter-value>
</parameter>
<parameter>
<parameter-name>systemType</parameter-name>
<parameter-value><![CDATA[PUSHDIARYTOLIF]]></parameter-value>
</parameter>
<parameter>
<parameter-name>systemType</parameter-name>
<parameter-value><![CDATA[PUSHDIARYTOSOC]]></parameter-value>
</parameter>
<parameter>
<parameter-name>systemType</parameter-name>
<parameter-value><![CDATA[PUSHDIARYTOTEC]]></parameter-value>
</parameter>
<parameter>
<parameter-name>diary.categoryId</parameter-name>
<parameter-value><![CDATA[]]></parameter-value>
</parameter>
</parameters>
本文地址:http://www.45fan.com/bcdm/72344.html