-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser_tootukassa.py
50 lines (38 loc) · 1.72 KB
/
parser_tootukassa.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
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Töötukassa RSS-voo sisendite parsimine
"""
import parsers_common
def getArticleListsFromHtml(pageTree, domain, maxPageURLstoVisit):
"""
Meetod saidi pakkumiste nimekirja loomiseks
"""
articleDescriptions = []
articleIds = []
articleImages = []
articlePubDates = []
articleTitles = pageTree.xpath('//table[@class="footable"]/tbody/tr/td[1]/a/strong/text()')
articleUrls = pageTree.xpath('//table[@class="footable"]/tbody/tr/td[1]/a/@href')
articleDescName = pageTree.xpath('//table[@class="footable"]/tbody/tr/td[1]/text()[2]')
articleDescLoc = pageTree.xpath('//table[@class="footable"]/tbody/tr/td[4]/text()')
articlePubDatesRaw = pageTree.xpath('//table[@class="footable"]/tbody/tr/td[2]/text()')
for i in range(0, len(articleUrls)):
articleUrl = articleUrls[i]
# get unique id from articleUrl
articleIds.append(articleUrl.split('-')[-1])
# descriptions
articleDescriptions.append(parsers_common.toPlaintext(articleDescName[i]) + "<br>" + parsers_common.toPlaintext(articleDescLoc[i]))
# timeformat magic from "12.12.2017" to datetime()
curArtPubDate = articlePubDatesRaw[i]
curArtPubDate = parsers_common.rawToDatetime(curArtPubDate, "%d.%m.%Y")
articlePubDates.append(curArtPubDate)
# titles
articleTitles[i] = parsers_common.toPlaintext(articleTitles[i]).capitalize()
return {"articleDescriptions": articleDescriptions,
"articleIds": articleIds,
"articleImages": articleImages,
"articlePubDates": articlePubDates,
"articleTitles": articleTitles,
"articleUrls": articleUrls,
}