-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (34 loc) · 1.05 KB
/
main.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
# -*- coding: utf-8 -*-
url='https://saglik.sozlugu.org/random-ajax/'
import urllib.request
from bs4 import BeautifulSoup
import time
import random
import os
toplam=0
i=0
bulunamamaAdedi=0
while True:
if bulunamamaAdedi>40:
break
i+=1
a=time.time()
page = urllib.request.urlopen(url)
soup = BeautifulSoup(page.read(), 'html.parser')
yazi=soup.text.replace("ç","ç").replace(",\n",", ")
yazi=yazi.strip()[:-1].strip().capitalize()
baslik=yazi.split("\n")[0]
dizin="Kelimeler\\"+baslik.capitalize().replace("/","")+".txt"
if not os.path.isfile(dizin):
print(f"{baslik}\ntoplam: {i}, süre: {round(toplam,2)}, ortalama: {round(toplam/i,2)}, bulunamama: {bulunamamaAdedi}")
bulunamamaAdedi=0
text_file = open(dizin, "w",encoding="UTF-8")
text_file.write(yazi)
text_file.close()
#print("-"*10+"\n")
time.sleep(random.uniform(0,1))
else:
print(baslik,"zaten var.")
bulunamamaAdedi+=1
toplam+=time.time()-a
print("Bu iş bu kadar mı?")