标签:
# -.- coding:utf-8 -.- from tornado.httpclient import HTTPClient # 这是一个读取网页的函数.(sync) def synchronous_fetch(url): """ 官方原话: Here is a sample synchronous function: 使用方法: print synchronous_fetch(‘http://www.qq.com‘) """ # 实例化(启动)一个HTTP客户端 http_client = HTTPClient() # 访问目标网址, 并将整个网站返回的内容 # 进行结构化保存(也就是将对方服务器返回的内容 # 拆分成header、body、buffer、code等信息) # print "headers", response.headers # print "code", response.code # print "buffer", response,buffer # print "error", response.error # print "reason", response.reason # print "request", response.request # print "request_time", response.request_time # print "time_info", response.time_info # print "rethrow", response.rethrow response = http_client.fetch(url) # 返回网站文本的body段内容. return response.body if __name__ == ‘__main__‘: print(synchronous_fetch(‘http://www.qq.com‘))
标签:
原文地址:http://my.oschina.net/u/2452965/blog/513523