声明式Web分析器
soupstars的Python项目详细描述
汤星:炖::星::繁荣:
soup stars是一个用python构建web解析器的框架。它的目的是通过简化开始所需的内容,使构建、部署和调度web解析器变得更容易。
快速启动
用PIP安装。
pip install soupstars
使用soupstars
命令创建一个新的解析器。create
命令将使用模板解析器。
soupstars create -m myparser.py
解析器是简单的python模块。
cat myparser.py
注意,唯一需要设置的是要解析的网页的特殊parse
装饰器和名为url
的变量。
fromsoupstarsimportparseurl="https://corbettanalytics.com/"@parsedefh1(soup):returnsoup.h1.text
您可以测试解析器是否正常工作。
soupstars test -m myparser.py
输出是一个json对象。
{"data":{"h1":"Level up your analytics"},"errors":{},"status":200,"url":"https://corbettanalytics.com/"}
cli中提供了更多功能。键入soupstars --help
查看命令列表
Usage: soupstars [OPTIONS] COMMAND [ARGS]...
CLI to interact with SoupStars cloud.
Options:
--help Show this message and exit.
Commands:
config Print the configuration used by the client
create Create a new parser from a template
health Print the status of the SoupStars api
login Log in with an existing email
ls Show the parsers uploaded to SoupStars cloud
pull Pull a parser from SoupStars cloud into a local module
push Push a parser to SoupStars cloud
register Register a new account on SoupStars cloud
run Run a parser on SoupStars cloud
show Show the contents of a parser on SoupStars cloud
test Test running a parser locally
version Print the SoupStars version in use
whoami Print the email address of the current user
部署到Soupstars.cloud
您可以部署要在我们的服务上运行的解析器。
使用cli创建帐户。系统将提示您输入用户名和密码。
soupstars register
上传你的分析器。
soupstars push -m myparser.py
现在您可以从我们的服务运行解析器。
soupstars run -m myparser.py
输出是一个json对象。
{"data":{"data":{"h1":"Level up your analytics"},"errors":{},"status":200,"url":"https://corbettanalytics.com/"},"id":"2bd746f6-ae14-4057-8af8-f92aa5d304ca","parser_id":"cb25aa3b-375d-4d55-966b-99cfef6e4015","status_code":200,"user_id":1}
开发
使用python3.6创建虚拟环境
virtualenv venv --python=python3.6
以开发模式安装软件包。
venv/bin/pip3 install --requirement requirements.txt
venv/bin/pip3 install --editable .
运行测试。
venv/bin/pytest -v
venv/bin/flake soupstars examples