scraper和web界面。
gsicrawler的Python项目详细描述
GSICrawler公司
GSICrawler是一种从多个来源(如Twitter、Facebook和新闻媒体)提取信息的服务。在
GSICrawler在后台使用这些服务:
- scraper/tasks(web)的httpapi。这是面向公众的部分,您将与用户交互。
- 芹菜(花)的前端
- 处理任务的后端(芹菜)
- 芹菜后端(redis)的代理
有几个scraper可用,每个scraper接受一组不同的参数(例如一个查询、最大数量的结果等)。 结果可以以任何格式存储在服务器上。 有些结果需要很长时间才能处理。 如果是这样,API将返回有关正在运行的任务的信息,因此您可以稍后查询服务以获得结果。 请阅读您感兴趣的刮刀的API规范。在
示例:
# Scrape NYTimes for articles containing "terror", and store it in an elasticsearch endpoint (`http://elasticsearch:9200/crawler/news`).
$ curl -X GET --header 'Accept: application/json' 'http://0.0.0.0:5000/api/v1/scrapers/nyt/?query=terror&number=5&output=elasticsearch&esendpoint=elasticsearch&index=crawler&doctype=news'
{
"parameters": {
"number": 5,
"output": "elasticsearch",
"query": "terror"
},
"source": "NYTimes",
"status": "PENDING",
"task_id": "bf5dd994-9860-4c63-975e-d09fb85a463c"
}
# The task
$ curl --header 'Accept: application/json' 'http://0.0.0.0:5000/api/v1/tasks/bf5dd994-9860-4c63-975e-d09fb85a463c'
{
"results": "Check your results at: elasticsearch/crawler/_search",
"status": "SUCCESS",
"task_id": "bf5dd994-9860-4c63-975e-d09fb85a463c"
}
说明书
有些爬虫需要API密钥和机密才能工作。
您可以使用此目录中的.env
文件在本地配置服务。
应该是这样的:
环境变量就位后,运行:
docker compose up
这将使用默认配置启动所有必要的服务。 此外,它还将部署一个elasticsearch实例,用于存储爬虫的结果。在
您可以使用OpenAPI仪表板在浏览器中测试服务:http://localhost:5000/
缩放和分布
为了便于部署,GSICrawler docker映像在一个容器中运行三个服务(web、flower和cellery后端)。
但是,可以通过使用不同的命令(默认情况下是all
)并设置适当的环境变量来更改此行为:
GSICRAWLER_BROKER=redis://localhost:6379
GSICRAWLER_RESULT_BACKEND=db+sqlite:///usr/src/app/results.db
# If results_backend is missing, GSICRAWLER_BROKER will be used
开发新刮板
撰写本文时,要向GSICrawler添加新的scraper,您需要:
- 开发刮削功能
- 向
gsicrawler/tasks.py
文件添加任务 - 将任务添加到控制器(
gsicrawler/controllers/tasks.py
) - 将新端点添加到API(
gsicrawler-api.yaml
)。在 - 如果您使用的是环境变量(例如API密钥),请将它们添加到
.env
文件中。在
如果您还使用CI/CD和/或Kubernetes来部署:
- 将任何新的环境变量添加到部署文件(
k8s/gsicrawler-deployment.yaml.tmpl
) - 将变量添加到CI/CD环境(例如https://docs.gitlab.com/ee/ci/variables/)
故障排除
Elasticsearch可能在启动时崩溃并抱怨vm.max_堆计数. 这将暂时解决此问题,直到下次启动:
sudo sysctl -w vm.max_map_count=262144
如果要使其永久化,请在/etc/sysctl.conf
中设置该值。在
- 项目
标签: