def getData(): db = DB() # get article article = db.one("SELECT * FROM article WHERE date=?", (getToday(), )) if article is not None: # pic TEXT, content TEXT article = {'pic': article[1], 'content': article[2]} # get music music = db.one("SELECT * FROM music WHERE date=?", (getToday(), )) if music is not None: # name TEXT, artist TEXT, pic TEXT, link TEXT music = { 'name': music[1], 'artist': music[2], 'pic': music[3], 'link': music[4] } # get movie movie = db.one("SELECT * FROM movie WHERE date=?", (getToday(), )) if movie is not None: # name TEXT, pic TEXT, type TEXT, score INT, plot TEXT, link TEXT movie = { 'name': movie[1], 'pic': movie[2], 'type': movie[3], 'score': movie[4], 'plot': movie[5], 'link': movie[6] } return {'article': article, 'music': music, 'movie': movie}
def get_db(data_clearing): """关于其作用域请移步查看官方文档""" try: db = DB() yield db finally: db.close()
def get_db(): """关于其作用域请移步查看官方文档""" try: db = DB() yield db finally: db.close()
def get_db(): """ :return: """ try: db = DB() yield db finally: db.close()
import sys sys.path.append('..') from tools.spider import Spider from tools.db import DB from tools.public import * from lxml import etree url = 'http://wufazhuce.com/' if __name__ == '__main__': spider = Spider() html = spider.crawl(url) selector = etree.HTML(html) url = selector.xpath('//div[@class="carousel-inner"]/div[@class="item active"]/a/img/@src') text = selector.xpath('//div[@class="carousel-inner"]/div[@class="item active"]/div[@class="fp-one-cita-wrapper"]/div[@class="fp-one-cita"]/a/text()') url = url[0] if len(url) == 1 else "" text = text[0] if len(text) == 1 else "" db = DB() select = db.one("SELECT * FROM article WHERE date=?", (getToday(),)) if select is None: insertData = (getToday(), url, text) db.execute("INSERT INTO article VALUES (?, ?, ?)", insertData)
def get_db(): """关于其作用域请移步查看官方文档""" db = DB() yield db db.close()