web.py 是python的一个web插件,用于发布web服务
安装
下载web.py
https://github.com/webpy/webpy
安装
解压下载的rar
打开控制台并定位到此文件夹
输入
python setup.py install
如果报错,则一般是需要县安装setuptools
https://pypi.python.org/pypi/setuptools
点击下载
https://pypi.python.org/packages/fd/e2/6685fa17489a921804951bdeb13faa177cd1095da91d9371c4908c903367/setuptools-26.0.0.zip#md5=6187d556fc96d2c4d17eb55a7f2ab504
解压到文件夹,cmd窗口定位到该文件夹
使用
python setup.py install
命令安装 setuptools
setuptools安装成功后定位到 web.py 文件夹 使用命令行 python setup.py install 安装 webpy
以下是测试代码
# -*- coding:utf-8 -*- import web,urllib,urllib2 urls =( '/','Index', '/s','So', ) render = web.template.render('templates') def baidu(wd): url = "https://www.baidu.com/s?wd={0}".format(wd) req = urllib2.Request(url) req.add_header('user-agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'); req.add_header('cache-control', 'no-cache'); req.add_header('accept', '*/*'); #req.add_header('accept-encoding', 'gzip, deflate'); req.add_header('connection', 'keep-alive'); response = urllib2.urlopen(req) the_page = response.read() #print the_page return the_page class Index(object): def GET(self): return 'Hello world' class So(object): def GET(self): data = web.input() wd = data.get('wd') page = baidu(wd) return page if __name__ == '__main__': web.application(urls,globals()).run()