-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportali.py
517 lines (373 loc) · 17.4 KB
/
portali.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
from bs4 import BeautifulSoup
import requests
import re
import meaningcloud
import nltk
import pdb
headers = {}
headers['User-agent'] = "HotJava/1.1.2 FCS"
#obrisat
#tportal
#index formating
#url="https://www.index.hr/vijesti/clanak/policija-za-index-muskarci-s-majicama-zds-nisu-privedeni-jer-je-padala-kisa/2179630.aspx"
license_key= "3668d6e355b00b38ff7d1b46c45c97de"
get_fibo = False
number_categories = 3
# @param topics_relevance - Relevance used for filtering entities and concepts
topics_relevance = 80
cluster_score_threshold = 50
# auxiliary variables to follow progress of the process
index_count = 1
total_files = None
# def getSummarization(text, sentences):
# # We are going to make a request to the Summarization API
# summary = ''
# print("\tGetting automatic summarization...")
# summarization_response = meaningcloud.SummarizationResponse(meaningcloud.SummarizationRequest(license_key, sentences=sentences, txt=text).sendReq())
# if summarization_response.isSuccessful():
# summary = summarization_response.getSummary()
# else:
# print("\tOops! Request to Summarization was not succesful: (" + summarization_response.getStatusCode() + ') ' + summarization_response.getStatusMsg())
# return summary
url="https://www.index.hr/vijesti/clanak/stozer-objavio-imamo-219-novih-slucajeva-2-osobe-umrle/2206278.aspx"
def index_parser(url):
excluded=["Scribd"]
r=requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for tag in soup.find_all("em"):
tag.decompose()
clanak= soup.find("div",{"class":"text"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if not element.text.endswith("."):
sadrzaj += f">{element.text}." +"\n\n"
elif element.find("strong") is not None:
sadrzaj+= f">**{element.text}**" +"\n\n"
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
# vec_url="https://www.vecernji.hr/vijesti/ja-sad-idem-kazao-je-supruzi-ljerki-dvije-je-godina-tragala-za-njim-1398430"
def vecernji_parser(vec_url):
r=requests.get(vec_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak= soup.find("div",{"class":"article__body--main_content"}).find_all("p")
for element in clanak:
#element = re.sub(">`","",element.text)
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
jut_url= "https://www.jutarnji.hr/vijesti/hrvatska/beros-iznenaden-velikim-brojem-novozarazenih-trudimo-se-naci-nacin-kako-to-zaustaviti-15014576"
def jutarnji_parser(jut_url):
print(jut_url) # obrisat
r=requests.get(jut_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
clanak= soup.find("div",{"class":"itemFullText"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.name=="h1":
sadrzaj+=f"{element.text}." +"\n"
if element.name=="h2":
sadrzaj+=f"{element.text}."+ "\n"
# if element.name == "h3":
# sadrzaj+=f"###{element.text}" +"\n"
if element.name=="h4":
sadrzaj+=f"{element.text}."+ "\n"
else:
element = element.text.strip("-")
sadrzaj += f">{element}"+"\n\n"
return sadrzaj
# clanak=jutarnji_parser(jut_url)
# print(clanak)
#rtl_url="https://www.rtl.hr/vijesti-hr/vijesti/3812727/onkoloska-pacijentica-ispred-rebra-ljudi-stoje-u-kilometarskim-redovima-bez-case-vode-na-hladnoci/"
def rtl_parser(rtl_url):
r=requests.get(rtl_url)
soup = BeautifulSoup(r.content, 'html.parser')
for item in soup.findAll("p"):
atag=item.find_all("a")
for a in atag:
a.decompose()
sadrzaj=""
clanak= soup.find("div",{"class":"Article-meteredContent"}).find_all(["p","h1","h3"])
for element in clanak:
if "(RTL)" in element.text:
pass
else:
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
_24sata_url="https://www.24sata.hr/sport/kakav-majstor-vlasic-u-derbiju-zabio-eurogol-lovrenu-i-zenitu-711833"
def d24sata_parser(_24sata_url):
r=requests.get(_24sata_url)
soup = BeautifulSoup(r.content, "html.parser")
# print(soup.prettify())
sadrzaj=""
clanak= soup.find("div",{"class":"article__text"}).get_text()
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
clanak = re.sub('<[^<]+?>', '', clanak)
return clanak.strip()
n1_url="http://hr.n1info.com/Vijesti/a536658/Ministrica-Brnjac-Ne-mozemo-odmah-nakon-uvodjenja-mjera-ocekivati-pad-zarazenih.html"
def n1_parser(n1_url):
r=requests.get(n1_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for item in soup.find_all("p",{"class":"time"}):
item.decompose()
clanak= soup.find("div",{"class":"single-article-content"}).find_all(["p","h1","h2","h3"])
for element in clanak[1:-1]:
if "OVDJE" not in element.text:
sadrzaj += f">{element.text}" +"\n\n"
sadrzaj=sadrzaj.split("N1 pratite",1)[0]
return sadrzaj
telegram_url = "https://www.telegram.hr/politika-kriminal/upoznajte-bracu-macan-drzava-im-daje-13-milijuna-kuna-za-fake-news-portal-prodaju-lazne-ankete-i-ustaske-majice/"
def telegram_parser(telegram_url):
r = requests.get(telegram_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find_all(["p", "h1", "h2", "h3"])
for element in clanak[3:-9]:
if element.name == "h1":
sadrzaj += f"> **{element.text}.**" +"\n"
if element.name == "h2":
sadrzaj += f">{element.text}." +"\n"
elif element.text in sadrzaj:
pass
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
#net.hr
# narod_url="https://narod.hr/kultura/video-1-svibnja-1995-operacija-bljesak-svanulo-sunce-hrvatske-slobode-koju-su-sanjale-generacije-hrvata"
# def narod_parser(narod_url):
# s=requests.session()
# r=s.get(narod_url, headers=headers)
# soup = BeautifulSoup(r.content, 'html.parser')
# sadrzaj=""
# clanak= soup.find("div",{"class":"td-ss-main-content"})#.find_all("p")
# print(soup.pretti>y())
# # for element in clanak:
# # sadrzaj += {element}.text +"\n"
# # print (sadrzaj)
# narod_parser(narod_url)
#hr_danas_url="https://hrvatska-danas.com/2020/05/01/milanovic-u-okucanima-poznatom-hos-ovcu-rekao-mrs-u-policiju-privedeni-hrvatski-ratni-veterani/"
def hr_danas_parser(hr_danas_url):
r=requests.get(hr_danas_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak= soup.find("div",{"class":"entry-content clearfix"}).find_all("p")
for element in clanak[:-8]:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
#dnevnik_url="https://dnevnik.hr/vijesti/hrvatska/davor-bernardic-o-incidentu-u-okucanima---603861.html"
def dnevnik_parser(dnevnik_url):
r=requests.get(dnevnik_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak= soup.find("div",{"class":"article-body-in"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak[:-6]:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
#novilist_url="http://www.novilist.hr/Vijesti/Svijet/SVEDSKI-EPIDEMIOLOG-JOHAN-GIESECKE-Europa-je-napravila-gresku-i-platit-ce-cijenu-cjepiva-ce-na-kraju-biti-uzaludna"
def novilist_parser(novilist_url):
r=requests.get(novilist_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak= soup.find("div",{"id":"article-text"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
# if element.n>me=="h1":
# sadrzaj+=f"#{element.text}" +"\n"
if element.name=="h3":
sadrzaj+=f"{element.text}"+ "\n"
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
slobodna_url="https://slobodnadalmacija.hr/vijesti/hrvatska/ante-tomic-crvena-zvijezda-ima-svako-pravo-stajati-nad-rijekom-to-da-se-grad-ne-zove-fiume-iskljucivo-je-partizanska-zasluga-1045910"
def slobodna_parser(slobodna_url):
r=requests.get(slobodna_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
clanak= soup.find("div",{"class":"itemFullText"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
# if element.name=="h1":
# sadrzaj+=f"#{element.text}" +"\n"
if element.name=="h3":
sadrzaj+=f"**{element.text}**"+ "\n"
else:
sadrzaj += f"{element.text}" +"\n\n"
return (sadrzaj)
#glasistre_url="https://www.glasistre.hr/svijet/bih-rusko-veleposlanstvo-zacudeno-odbijanjem-dolaska-njihovih-vojnika-640701"
def glasistre_parser(glasistre_url):
r=requests.get(glasistre_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
clanak= soup.find("div",{"id":"CloudHub_Element_Content"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
# if element.name=="h1":
# sadrzaj+=f"#{element.text}" +"\n"
if element.name=="h3":
sadrzaj+=f">{element.text}"+ "\n"
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
#nacional_url="https://www.nacional.hr/okrivljenici-za-palez-vikendice-radovana-ortynskog-izlaze-iz-pritvora/"
def nacional_parser(nacional_url):
r=requests.get(nacional_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
clanak= soup.find("div",{"class":"entry-content clearfix"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
# if element.name=="h1":
# sadrzaj+=f"#{element.text}" +"\n"
if element.name=="h3":
sadrzaj+=f">{element.text}"+ "\n"
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj[:-12])
nethr_url = "https://net.hr/danas/hrvatska/grlic-radman-otvorio-restoran-u-svom-ministarstvu-posao-firmi-zanimljivo-povezanoj-s-megatvrtkom-u-vlasnistvu-obitelji-ministra/"
def nethr_parser(nethr_url):
s = requests.session()
r = s.get(nethr_url, headers=headers)
# r=requests.get(nethr_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
clanak = soup.find_all(["p", "h1", "h2", "h3", "h4", "h5"])
for element in clanak[7:-75]:
sadrzaj += f">{element.text}" + "\n\n"
return (sadrzaj)
#tportal_url="https://www.tportal.hr/vijesti/clanak/detalji-nesrece-kod-zemunika-poginuo-clan-krila-oluje-i-kadet-koji-je-tek-poceo-s-letackom-obukom-20200507"
def tportal_parser(tportal_url):
r=requests.get(tportal_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
for strong in soup.find_all("strong"):
strong.replaceWith(f"**{strong.text}**")
for item in soup.find_all("figcaption",{"class":"meta"}) or soup.find_all("figcaption",{"class":"meta"}):
item.decompose()
clanak= soup.find_all("div",{"class":"introComponent"}) + soup.find("section",{"class":"articleComponents"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
# if element.name=="h1":
# sadrzaj+=f"#{element.text}" +"\n"
if element.name=="h3":
sadrzaj+=f">{element.text}"+ "\n"
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
#ampindex_url="https://amp.index.hr/article/2180444/stadion-maksimir-privremeno-neupotrebljiv-dobio-zutu-oznaku-urusava-se-godinama"
def ampindex_parser(ampindex_url):
excluded=["Scribd"]
r=requests.get(ampindex_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak= soup.find("div",{"class":"articleText"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") != None:
sadrzaj+= f"> **{element.text}**" +"\n\n"
else:
sadrzaj += f">{element.text}" +"\n\n"
return (sadrzaj)
#sportnet_url = "https://sportnet.rtl.hr/vijesti/541514/vodeni-sportovi-jedrenje/jedrilicari-i-skiperi-najtrazeniji-smjer-ovog-ljeta-na-kif-u/"
def sportnet_parser(sportnet_url):
r=requests.get(sportnet_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak = soup.find("div", {"class":"st1"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak[1:-5]:
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
dal_danas_url = "https://www.dalmacijadanas.hr/turisti-gledali-u-soku-zena-razmazala-govna-po-kipu-grgura-to-je-sotona/"
def dal_danas_parser(dal_danas_url):
s=requests.session()
r=s.get(dal_danas_url, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj=""
clanak = soup.find("div", {"class":"td-ss-main-content"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
hrt_magazin_url = "https://magazin.hrt.hr/645384/price-iz-hrvatske/more-na-sest-dubrovackih-plaza-onecisceno-fekalijama"
def hrt_magazin_parser(hrt_magazin_url):
r = requests.get(hrt_magazin_url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("div", {"class": "body"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") is not None:
sadrzaj += f"> **{element.text}**" +"\n\n"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
maxurl = "https://www.maxportal.hr/sport/mec-za-pamcenje-coric-spasio-sest-mec-lopti-za-osminu-finala-us-opena-video/"
def maxportal_parser(url):
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("div", {"class":"post_content"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") is not None:
sadrzaj += f"> **{element.text}**" +"\n\n"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
bug_url = "https://www.bug.hr/najava/new-world-azothara-na-aeternumu-mora-da-je-sala-16386"
def bug_parser(url):
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("div", {"class":"post-full__content"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") is not None:
sadrzaj += f"> **{element.text}**" +"\n\n"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
dalport_url = "https://dalmatinskiportal.hr/vijesti/festival/74323?fbclid=IwAR0EsUG3cGHByFUsh6WU5jj5G8sc1z5P_tXu5PavQvJze4jlAIV5_-sSNjM"
def dalportal_parser(url):
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("div", {"class":"open_article_content"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") is not None:
sadrzaj += f"> **{element.text}**" +"\n\n"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
poslovni_url = "https://www.poslovni.hr/europska-unija/uskoro-stize-europska-minimalna-placa-evo-o-cemu-je-zapravo-rijec-i-koliko-bi-trebao-porasti-minimalac-kod-nas-4251627"
def poslovni_parser(url):
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("article", {"class":"single__inner"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") is not None:
sadrzaj += f"> **{element.text}**" +"\n\n"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj
kamenjar_url = "https://kamenjar.com/na-danasnji-dan-oba-su-pala-jedna-od-najpoznatijih-video-snimki-iz-domovinskog-rata/"
def kamenjar_parser(url):
headers = {}
headers['User-agent'] = "HotJava/1.1.2 FCS"
s = requests.session()
r = s.get(url, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("div", {"id":"mvp-content-main"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak:
if element.find("strong") is not None:
sadrzaj += f"> **{element.text}**" +"\n\n"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj[:-57]
def direktno_parser(url):
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
sadrzaj = ""
clanak = soup.find("div", {"class":"main-content"}).find_all(["p","h1","h2","h3","h4","h5"])
for element in clanak[0:2] + clanak[5:-3]:
# if element.find("strong") is not None:
# sadrzaj += f"> **{element.text}**"
sadrzaj += f">{element.text}" +"\n\n"
return sadrzaj