#------------------------------------------------------------------------------
# generate the full url, which include the main url plus the parameter list
# Note:
# normally just use urllib.urlencode is OK.
# only use this if you do NOT want urllib.urlencode convert some special chars($,:,{,},...) into %XX
def genFullUrl(mainUrl, paraDict) :
fullUrl = mainUrl;
fullUrl += '?';
for i, para in enumerate(paraDict.keys()) :
if(i == 0):
# first para no '&'
fullUrl += str(para) + '=' + str(paraDict[para]);
else :
fullUrl += '&' + str(para) + '=' + str(paraDict[para]);
return fullUrl;
例 2.7. genFullUrl的使用范例
# Note: here not use urllib.urlencode to encode para,
# for the encoded result will convert some special chars($,:,{,},...) into %XX
paraDict = {
'asyn' : '1',
'thread_id_enc' : '',
'start' : '',
'count' : '',
'orderby_type' : '0',
};
paraDict['thread_id_enc'] = str(threadIdEnc);
paraDict['start'] = str(startCmtIdx);
paraDict['count'] = str(reqCmtNum);
paraDict['t'] = str(cmtReqTime);
mainUrl = "http://hi.baidu.com/cmt/spcmt/get_thread";
getCmtUrl = genFullUrl(mainUrl, paraDict);





