-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (28 loc) · 944 Bytes
/
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
from flask import Flask, render_template, request
import wikipedia
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/results", methods = ['POST'])
def wiki():
if request.method == 'POST':
term = request.form['term']
data = wikipedia.summary(str(term))
imgurllist = img(term.replace(" ",""))
return render_template("result.html",term = term, data = data, imgurllist = imgurllist, l=len(imgurllist))
else:
return render_template('result.html')
def img(term):
html = urlopen('https://en.wikipedia.org/wiki/{}'.format(term))
bs = BeautifulSoup(html, 'html.parser')
images = bs.find_all('img', {'src':re.compile('.jpg')})
lst=[]
for i in images:
lst.append(str(i['src']))
return lst
if __name__ == "__main__":
app.run(debug=True)