@@ -43,12 +43,21 @@ def get_URL():
43
43
url = 'https://stackoverflow.com/questions/tagged/{}?sort=MostVotes&edited=true' .format (tag )
44
44
return url
45
45
46
+ def number_questions ():
47
+ questions = int (questions_box .get ())
48
+ if type (questions ) != int or questions > 15 :
49
+ return 15
50
+ return questions
51
+
46
52
def scrape_questions ():
47
53
for count in range (5 ):
48
54
progress ['value' ] += 15
49
55
window .update_idletasks ()
50
56
time .sleep (0.10 )
51
57
58
+ question_count = number_questions ()
59
+ count = 0
60
+
52
61
url = get_URL ()
53
62
if url :
54
63
page = requests .get (url )
@@ -64,6 +73,8 @@ def scrape_questions():
64
73
clear_progress ()
65
74
return ""
66
75
for question in questions :
76
+ if count >= question_count :
77
+ break
67
78
question_text = question .find ('a' , {'class' : 'question-hyperlink' }).text .strip ()
68
79
question_summary = question .find ('div' , {'class' : 'excerpt' }).text .strip ()
69
80
question_summary = question_summary .replace ('\n ' ,' ' )
@@ -72,6 +83,7 @@ def scrape_questions():
72
83
views = question .find ('div' , {'class' : 'views' }).text .strip ().split ()[0 ]
73
84
entities = (question_text , question_summary , question_link , votes , views )
74
85
sql_insert (con , entities )
86
+ count += 1
75
87
76
88
messagebox .showinfo ("Success!" , "Questions scrapped successfully!" )
77
89
clear_progress ()
@@ -143,23 +155,30 @@ def clear_progress():
143
155
background = 'white' , foreground = "Orange" ,
144
156
font = ("Helvetica" , 30 , 'bold' )).grid (row = 0 , column = 1 )
145
157
146
- # label for combobox
158
+ # label texts
147
159
ttk .Label (window , text = "Enter tag (ex - python):" , background = 'white' ,
148
160
font = ("Helvetica" , 15 )).grid (column = 0 ,
149
161
row = 5 , padx = 10 , pady = 25 )
150
162
163
+ ttk .Label (window , text = "No of questions to scrape:" , background = 'white' ,
164
+ font = ("Helvetica" , 15 )).grid (column = 0 ,
165
+ row = 6 , padx = 10 , pady = 5 )
166
+
151
167
152
168
# Button creation
153
169
scrape_btn = ttk .Button (window , text = "Scrape questions!" , style = 'my.TButton' , command = scrape_questions )
154
170
scrape_btn .grid (row = 5 , column = 2 , pady = 5 , padx = 15 , ipadx = 5 )
155
171
156
172
display_btn = ttk .Button (window , text = "Display from DB" , style = 'my.TButton' , command = show_results )
157
- display_btn .grid (row = 7 , column = 2 , pady = 5 , padx = 15 , ipadx = 5 )
173
+ display_btn .grid (row = 6 , column = 2 , pady = 5 , padx = 15 , ipadx = 5 )
158
174
159
175
# Search Box
160
176
search_box = tk .Entry (window , font = ("Helvetica 15" ), bd = 2 , width = 60 )
161
177
search_box .grid (row = 5 , column = 1 , pady = 5 , padx = 15 , ipadx = 5 )
162
178
179
+ questions_box = tk .Entry (window , font = ("Helvetica 15" ), bd = 2 , width = 60 )
180
+ questions_box .grid (row = 6 , column = 1 , pady = 5 , padx = 15 , ipadx = 5 )
181
+
163
182
frame = ttk .Frame (window , style = 'my.TFrame' )
164
183
frame .place (relx = 0.50 , rely = 0.18 , relwidth = 0.98 , relheight = 0.90 , anchor = "n" )
165
184
0 commit comments