web.py 是python的一個web插件,用於發佈web服務
安裝
下載web.py python
https://github.com/webpy/webpy
git
安裝github
解壓下載的rar
web
打開控制檯並定位到此文件夾
輸入 app
python setup.py install
若是報錯,則通常是須要縣安裝setuptools測試
https://pypi.python.org/pypi/setuptoolsurl
點擊下載
https://pypi.python.org/packages/fd/e2/6685fa17489a921804951bdeb13faa177cd1095da91d9371c4908c903367/setuptools-26.0.0.zip#md5=6187d556fc96d2c4d17eb55a7f2ab504spa
解壓到文件夾,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()