[Python3 网络爬虫开发实战] 1.6.1-Flask 的安装 | 珊瑚贝

Flask 是一个轻量级的 Web 服务程序,它简单、易用、灵活,这里主要用来做一些 API 服务。

1. 相关链接

2. pip 安装

这里推荐使用 pip 安装,命令如下:

1
pip3 install flask

运行完毕后,就完成安装了。

3. 验证安装

安装成功后,可以运行如下实例代码测试一下:

1
2
3
4
5
6
7
8
9
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

if __name__ == "__main__":
app.run()

可以发现,系统会在 5000 端口开启 Web 服务,控制台输出如下:

1
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

直接访问 http://127.0.0.1:5000/,可以观察到网页中呈现了 Hello World!,如图 1-41 所示,一个最简单的 Flask 程序就运行成功了。

图 1-41 运行结果

4. 结语

后面,我们会利用 Flask+Redis 维护动态代理池和 Cookies 池。

来源:https://cuiqingcai.com/5244.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_11553.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?