web.py安装


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()

 

转载于:https://www.cnblogs.com/Leechg/p/5817657.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值