微慑信息网

python采集结果入库xiunobbs

xiunobbs作为一个轻量的便携系统,采集入库相对简单,记录下之前python采集入库xiunobbs的脚本,备忘:

def dbDeal(mTitle,mContext):
    conn= MySQLdb.connect(
        host='127.0.0.1',
        port = 3306,
        user='root',
        passwd='123456',
        db ='xiuno4',
        charset='utf8'
        )

    cur = conn.cursor()
    logger.info("[-]数据库链接成功...")
    #准备工作           
    #tid
    cur.execute('select tid from bbs_thread order by tid desc limit 0,1;')
    data = cur.fetchall()
    if len(data)==0:
        tid=0
    else:
        for m in data:
            tid = m[0]
    tid=tid+1
    mDate=str(int(time.time()))
    #插入内容   pid
    logger.info("[-]准备插入内容...")
    mysql1='insert into bbs_post (tid,uid,isfirst,create_date,userip,images,files,doctype,quotepid,message,message_fmt)  values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    cur.execute(mysql1,(tid,'1','1',mDate,'2130706433','0','0','1','0',mContext,mContext))
    cur.close()
    cur = conn.cursor()
    #插入标题 fid 板块    tid
    #pid
    logger.info("[-]准备插入标题...")
    cur.execute('select pid from bbs_post order by tid desc limit 0,1;')
    data = cur.fetchall()
    for m in data:
        pid = m[0]
    #pid=pid+1
    print pid
    mysql2='insert into bbs_thread (fid,top,uid,userip,subject,create_date,last_date,views,posts,images,files,mods,closed,firstpid,lastuid,lastpid)  values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    cur.execute(mysql2,('1','0','1','2130706433',mTitle,mDate,mDate,'0','0','0','0','0','0',pid,'0',pid))
   
    cur.close()
    conn.commit()
    #print str(mDate)+'-----------'+str(i)

    cur = conn.cursor()
    mysql3='update bbs_post set bbs_post.tid=(select bbs_thread.tid from bbs_thread where bbs_thread.firstpid=bbs_post.pid);'
    cur.execute(mysql3)
    cur.close()
    conn.commit()
    logger.info("[-]该条写入完成。")

 

本文标题:python采集结果入库xiunobbs
本文链接:
(转载请附上本文链接)
http://vulsee.com/archives/vulsee_2021/0120_13674.html
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » python采集结果入库xiunobbs
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

微慑信息网 专注工匠精神

访问我们联系我们