-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathted.py
More file actions
30 lines (22 loc) · 834 Bytes
/
Copy pathted.py
File metadata and controls
30 lines (22 loc) · 834 Bytes
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
import json
from urllib import request
from bs4 import BeautifulSoup as BS
def main(url):
page = request.urlopen(url)
soup = BS(page, 'html.parser')
author_title = str(
soup.find('title').get_text()).split('|')[0]
[author, title] = author_title.split(':')
body = str(soup.find('div', attrs={'class': 'p:2'}).get_text()).replace(
'\t', '').replace('(Risos)', '').replace('(Aplausos)', '').replace('(Vivas)', '').replace('\n', ' ')
obj = {
"author": author.strip(),
"body": body.strip(),
"title": title.strip(),
"type": "video",
"url": url
}
file_name = '_'.join(title.replace('.', '').strip().split(' ')) + '.json'
with open(file_name, 'w', encoding='utf8') as f:
json.dump(obj, f, indent=2, ensure_ascii=False)
return obj