-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
34 lines (25 loc) · 967 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
from crawler.db import session
from crawler.db.models import Site, create_tables
from crawler.spiders.kupujemprodajem import KupujemprodajemSpider
from crawler.spiders.nekretnine import NekretnineSpider
from crawler.spiders.polovniautomobili import PolovniautomobiliSpider
create_tables()
SPIDERS_MAP = {
"polovniautomobili.com": PolovniautomobiliSpider,
"kupujemprodajem.com": KupujemprodajemSpider,
"nekretnine.rs": NekretnineSpider,
}
def main():
process = CrawlerProcess(get_project_settings())
sites = session.query(Site).filter(Site.active.is_(True))
if sites.count() == 0:
print(
"No site urls added. " 'Use "python create_site_url.py" command to add url.'
)
for site in sites:
process.crawl(SPIDERS_MAP[site.site], site_id=site.id)
process.start()
if __name__ == "__main__":
main()