Python模块--练习题

在web性能测试中,我们经常需要度量一个transaction(事务)需要花费多长时间,通常开发人员会使用log4j 打印出事物的开始点和结束点。下面是个真实的log4j输出内容

 DEBUG 180106 21:58:51,607 Receiver_1#receive a new request,  the session id is 2018010610020809
 ….
 ….
 ….

 DEBUG 180106 21:59:38,908 Receiver_4#send response to client,  the session id is 2018010610020809
 sys.stdout=f
 计算出处理这个事务所花费的时间

# 输出log信息到同一个文件test.log上,要求log输出不同级别的log, 包括输出异常信息到log文件
import logging
logging.basicConfig(filename="test.log",filemode="w",format="%(asctime)s-%(name)s-%(levelname)s-%(message)s",level=logging.INFO)
logging.critical('critical')
logging.error('error')
logging.warning('warning')
logging.info('info')
logging.debug('debug'
# 查找/tomcat/log/ 目录下的log文件,如果文件最后修改时间是在1小时之前,把次文件打包压缩,备份到
# /home/back/log 目录下

# 搜索目录/home/tools/下所有已test开头,py结尾的文件(包括子目录的), 把文件全路径输出到一个列表里面打印出来
import sys,os
path=r'E:\python2104\day11\作业\homework'
# if path.startswith('test') and path.endswith('.py'):
for name in os.listdir(path):
    a= os.path.join(path,name)
    if path.startswith('test') or path.endswith('.py'):
        print(os.system(f'python {a}'))

使⽤requests第三⽅模块获得⽹上信息

1. pip install requests

2. 编写python⽂件

import requests
result=requests.get('https://www.hao123.com/?tn=02003390_68_hao_pg')
print(result.text)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值