r = requests.get(url='http://sports.sina.cn/nba/rockets/2015-10-07/detail-ifximrxn8235561.d.html?vt=4&pos=10')# 最基本的GET请求 r.encoding = 'utf-8' r = r.content print r
selector = etree.HTML(html) File "lxml.etree.pyx", line 2953, in lxml.etree.HTML (src\lxml\lxml.etree.c:66734) File "parser.pxi", line 1780, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:101591) ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
defisequal(output,right_output): if output == right_output: returnTrue else: printu'不相等'
那么恭喜你,你步入正规了,然而,这一切已经有人为你做好了。欢迎unittest模块出场。
unittest supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework. The unittest module provides classes that make it easy to support these qualities for a set of tests.
#-*-coding:utf-8-*- from flask import Flask app = Flask(__name__)
@app.route('/') def index(): f = open('mail_note.log','rb') #以读文件的方式打开mail_note.log文件 content = f.readlines()#按行读取日志 s = '' for each in content: s += each s += '</p>'#输出日志 f.close() return s
if __name__ == '__main__': app.run(host='0.0.0.0') #开发外网访问
#-*-coding:utf-8-*- from flask import Flask app = Flask(__name__)
@app.route('/') def index(): f = open('mail_note.log','rb') #以读文件的方式打开mail_note.log文件 content = f.readlines()#按行读取日志 s = '' for each in content: if 'gmail_helper.py' in each: #判定信息来自gmail_helper.py而不是discovery.py s += each s += '</p>'#输出日志 f.close() return s
if __name__ == '__main__': app.run(host='0.0.0.0') #开发外网访问