遍历ID从数据库获得需要的数据
import pymysql
import re
import linecache
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='123456',
db='test',
charset='utf8',
)
cursor = conn.cursor()
sql1=cursor.execute("select article_id from article")
info=cursor.fetchmany(sql1)#获取查询结果
#遍历id获得id对应的文件地址,取出并在本机搜索读取
for i in info:
sql = cursor.execute('select article_address from article where article_id=%d'%i)
info = cursor.fetchmany(sql)
f = open(info[0][0], "r",encoding = 'utf-8')
f=f.read()
sql=cursor.execute("select bds_id from bds")
info=cursor.fetchmany(sql)#获取查询结果
for j in info:
sql=cursor.execute('select bds_expression from bds where bds_id=%d'%j)
info = cursor.fetchmany(sql)
aa=eval(info[0][0])
f_address=re.findall(aa,f)
f_address = "".join(f_address)
sql=cursor.execute('insert into print_out(print_out_content,bds_id,article_id) values("%s","%d","%d")'%(f_address,j[0],i[0]))
cursor.close()
conn.commit()#数据提交
conn.close()