import re
import urllib
import urllib2
import cookielib
sock = urllib.urlopen(url)
html = sock.read()
sock.close()
content = re.findall('(?<=blogstory">).*(?=<p class="right artical)', html, re.S)
content = re.findall('<script.*>.*</script>(.*)', content[0], re.S)
title = re.findall('(?<=<title>)(.*)-.* - CSDN.*(?=</title>)', html, re.S)
blog = {'spBlogTitle': title[0].decode('utf-8').encode('gbk'),
'spBlogText': content[0].decode('utf-8').encode('gbk'),
'ct': "1",
'cm': "1"}
del content
del title
cj = cookielib.CookieJar()
post_data = urllib.urlencode({'username': '[username]', 'password': '[password]', 'pwd': '1'})
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Opera/9.23')]
urllib2.install_opener(opener)
req = urllib2.Request(path, post_data)
conn = urllib2.urlopen(req)
bd = re.findall('(?<=bdstoken\" value=\").*(?=ct)', bd, re.S)
blog['bdstoken'] = bd[0][:32]
blog['spBlogCatName'] = 'php'
print urllib2.urlopen(req2).read()