提取oracle資料庫HTML內容轉換成正文格式
阿新 • • 發佈:2018-11-09
提取oracle資料庫HTML內容轉換成正文格式(去標籤)在更新到同表的TZNR
# -*- coding:utf-8 -*- import cx_Oracle from bs4 import BeautifulSoup conn = cx_Oracle.connect('使用者名稱', '使用者密碼', 'localhost:1521/ORCL') cur = conn.cursor() sql_search = 'select WZ,HTML from 表名' res = cur.execute(sql_search) # html = cur.fetchone() rows = cur.fetchall() #得到所有資料集 for row in rows: # print(row[0]) html = BeautifulSoup(row[1],'lxml').text # print(html) upsql = "UPDATE 表名 t SET t.TZNR = :TZNR WHERE t.WZ = :WZ" cur.prepare(upsql) cur.execute(None, {'TZNR': html,'WZ': row[0]}) print('sucess!!!') conn.commit() cur.close() conn.close()