-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetcontent.py
More file actions
25 lines (24 loc) · 865 Bytes
/
getcontent.py
File metadata and controls
25 lines (24 loc) · 865 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
import framler
import os
from underthesea import sent_tokenize
dt = framler.NewspapersParser("vnexpress")
with open("links.txt", "r") as f:
urls = f.readlines()
for url in urls:
print("Đang lấy bài báo thứ ", urls.index(url))
article = dt.parse(url)
# url.split("/")[3] trả về loại bài báo
directory_save = "data/" + url.split("/")[3]
# nếu folder chưa tồn tại thì tạo mới
if not os.path.exists(directory_save):
os.makedirs(directory_save,exist_ok=True)
# tách thành các câu
sentences = sent_tokenize(article.text)
# ghi các câu này thành dữ liệu
f = open(directory_save + "/" +"data.txt","w",encoding='utf-8')
# ghi url vào dòng đầu
f.write(url)
for sentence in sentences:
f.write(sentence+ "\n")
f.close()
print("Xong! ", urls.index(url))