-
Notifications
You must be signed in to change notification settings - Fork 4
/
template_spider.py
46 lines (29 loc) · 1.12 KB
/
template_spider.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
35
36
37
38
39
40
41
42
43
44
45
46
import scrapy
from datetime import datetime
from scrapy import cmdline
import sys
sys.path.insert(1, '../.')
from check_date import check_date
class TemplateSpider(scrapy.Spider):
name = "template"
def start_requests(self):
yield scrapy.Request(url='https://www.google.ca', callback=self.parse)
def parse(self, response):
for item in response.css('[]'):
date = item.css('[]::text').get()
date_obj = datetime.strptime(date, "").date()
if check_date(date):
yield {
'date': date,
'title': item.css('[]::text').get(),
'url': item.css('[] a::attr(href)').get(),
}
# ALSO UPDATE ...
# script.bash
# exporter_mac.py
# README.md
# Creates file with date and writes content to the file
# os.system("touch fcc_$(date +%m.%d.%y).csv")
date = datetime.today().strftime("%m.%d.%y")
execute = "scrapy runspider template_spider.py -O output/template_" + date + ".csv"
cmdline.execute(execute.split())