Python2.7编写的读取html中指定元素,并生成excle文件
代码如下:
#coding=gbk
import string
import codecs
import os,time
import xlwt
import xlrd
from bs4 import BeautifulSoup
from xlrd import open_workbook
class LogMsg:
def __init__(self,logfile,Level=0):
try:
import logging
#self.logger = None
self.logger = logging.getLogger()
self.hdlr = logging.FileHandler(logfile)
formatter = logging.Formatter("[%(asctime)s]: %(message)s","%Y%m%d %H:%M:%S")
self.hdlr.setFormatter(formatter)
self.logger.addHandler(self.hdlr)
#logger.setLevel()
if Level == 10:
self.logger.setLevel(logging.DEBUG)
elif Level == 20:
self.logger.setLevel(logging.INFO)
elif Level == 30:
self.logger.setLevel(logging.WARNING)
elif Level == 40:
新闻热点
疑难解答