-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplone_extract.py
46 lines (34 loc) · 1003 Bytes
/
plone_extract.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
import urllib2 as url
import json
import sys
import re
from bs4 import BeautifulSoup as bs
api_url = sys.argv[1]
print api_url
base_url = 'http://134.226.40.5:8080/ct4l/knowledge'
header = {'Content-Type': 'application/json'}
req = url.Request(base_url, None, header)
res = url.urlopen(req)
soup = bs(res.read())
res.close()
links = soup.find_all('a', 'summary url')
for l in links:
address = l.get('href')
req = url.Request(address, None, header)
res = url.urlopen(req)
page_soup = bs(res.read())
res.close()
title = page_soup.find(id='parent-fieldname-title').get_text()
description = page_soup.find(id='parent-fieldname-description').get_text()
description = description + page_soup.find('div', {'id' : re.compile('parent-fieldname-text.*')}).get_text()
data = {
'concept' : {
'name' : title,
'description' : description
}
}
address = api_url + '/concepts'
print address
req = url.Request(address, json.dumps(data), header)
res = url.urlopen(req)
res.close()