-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfact.py
More file actions
36 lines (30 loc) · 862 Bytes
/
fact.py
File metadata and controls
36 lines (30 loc) · 862 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
31
32
33
34
35
36
import tkinter
from tkinter import *
# import threading
import random
# from time import sleep
fw = open('fact.txt','r',encoding='gb18030',errors='ignore')
facts = fw.read()
facts = facts.split('\n')
def change():
i = random.randrange(2, len(facts) - 1)
text.delete(1.0,'end')
text.insert(END, facts[i])
i = random.randrange(2,len(facts)-1)
root = tkinter.Tk()
root.wm_attributes('-topmost',1)
root.title(facts[1])
text = Text(root,width=50,height=8)
text.insert(END,facts[i])
text.pack()
Button(root, text="change", command=change).pack()
root.mainloop()
'''
for i in range(10):
url = 'http://www.snapple.com/real-facts/list-view/'+str(i+1)
sc = requests.get(url)
soup = BeautifulSoup(sc.text,'lxml')
fact = soup.findAll('p',{'class':'fact_detail'})
for i in range(len(fact)):
fw.write(fact[i].text+'\n')
'''