scrapy 管理部署的爬虫项目的python类
# 测试浏览器弹窗的验证: import requests from urllib import parse import logging logging.basicConfig(level=logging.INFO) class ScrapyManager(object): def __init__(self, url, project_name, spider=None, username=None, pwd=None): self.url = url self.project_name = project_name self.spider = spider self.auth = (username, pwd) def start_project(self): """ 爬虫项目启动 :return: """ if not self.spider: raise Exception(‘未提供爬虫名称!‘) data = dict( project=self.project_name, spider=self.spider, ) start_url = parse.urljoin(self.url, ‘schedule.json‘) res = requests.post(url=start_url, data=data, auth=self.auth) logging.info(res.text) def del_project(self): """ 项目删除 :return: """ data = dict( project=self.project_name, spider=self.spider, ) start_url = parse.urljoin(self.url, ‘delproject.json‘) res = requests.post(url=start_url, data=data, auth=self.auth) logging.info(res.text) def stop_job(self, job_id): """ 停止任务 :param job_id: 任务id :return: """ data = dict( project=self.project_name, job=job_id, ) start_url = parse.urljoin(self.url, ‘cancel.json‘) res = requests.post(url=start_url, data=data, auth=self.auth) logging.info(res.text)
还有部分api接口没有添加进来,可以参照官方的文档添加.
相关推荐
zhuquan0 2020-05-25
class Singleton: def __new__: # 关键在于这,每一次实例化的时候,我们都只会返回这同一个instance对象 if not hasattr: cls.instance =
lhxxhl 2020-05-16
PHP学习笔记 2020-05-07
DCXabc 2020-05-01
bcbeer 2020-05-02
fly00love 2020-03-08
liusarazhang 2020-03-06
zhuxianfeng 2020-03-03
Kwong 2020-03-01
ladysosoli 2020-03-01
liugan 2020-02-25
Dimples 2020-02-14
wangqing 2020-02-13
fanhuasijin 2020-02-03
文山羊 2020-02-01