for i in range(my_range): cousor=cnx.cursor() sql_sentense="select * from url_content where place>=%s and place <%s" # place为id sql_stentese2="update url_content set flag1=3, attach_url=%s,content=%s where place =%s" #atturl为附件url所在的新字段,content为内容字段 cousor.execute(sql_sentense,(x,x+m)) str='' list1=[] for content in cousor.fetchall(): atturl_list=[] all_couple=[] str1=content[3] con_url=content[2] con_id=content[0] text = attatch_url(str1,con_url) str2=text.Replace_Char(str1) pre_url=text.get_url(str2) for i in pre_url: a=text.combin_url(text.get_domain(con_url,text.has_http(i)),i) atturl_list.append(a) all_couple.append((i,a)) for i in all_couple: str2=str2.replace(i[0],i[1]) if atturl_list: print [atturl_list,con_id] encodedjson = json.dumps(atturl_list) list1.append((encodedjson,str2,con_id))
for i in range(my_range): t6=time.time() cursor=cnx.cursor() sql_sentense="select * from url_content where place>=%s and place <%s" sql_sentense2='update url_content set flag1=1, attach_url=%s where place =%s' cursor.execute(sql_sentense,(x,x+m)) list1=[] str='' for content in cursor.fetchall(): # str='''<a href="/InvestmentInfo/ZhaoBiao/InviteNoticeDetail.aspx?id=127814">[email protected]<''' str=content[3] # url1=content[2] # print url1.encode('GBK','ignore') att_url=content[2] text = attatch_url(str,att_url) url=text.get_attatch_url() con_id=content[0] if url != []: encodedjson = json.dumps(url) list1.append((encodedjson,con_id)) else: list1.append((('',con_id))) # print list1 tuple_in=tuple(list1) # print tuple_in print x cursor.close() cursor2=cnx.cursor() cursor2.executemany(sql_sentense2,tuple_in) cnx.commit()