-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (72 loc) · 2.02 KB
/
Copy pathmain.py
File metadata and controls
87 lines (72 loc) · 2.02 KB
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
#from flask import Flask , jsonify
#from flask_restful import Resource, Api
#
#app = Flask(__name__)
#api = Api(app)
#
#@app.route('/getmethod/<jsdata>')
#def get_javascript_data(jsdata):
# return jsdata
#
#@app.route('/postmethod', methods = ['POST'])
#def get_post_javascript_data():
# jsdata = request.form['javascript_data']
# return jsdata
#
#from flask import Flask,request
#from flask_cors import CORS, cross_origin
#
#app = Flask(__name__)
#cors = CORS(app)
#app.config['CORS_HEADERS'] = 'Content-Type'
#
#@app.route('/hello', methods=['GET', 'POST'])
#@cross_origin()
#def hellohello():
# if request.method == "POST":
# text=request.form['text']
# return text
#
#if __name__ == "__main__":
# app.run()
from flask import Flask,request
from flask_cors import CORS, cross_origin
import json
import spacy
import urllib.request
from bs4 import BeautifulSoup
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/home', methods=['POST'])
def home():
if request.method == "POST":
def spacyFunction(name):
nlp = spacy.load("en_core_web_sm")
punc = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
for ele in name:
if ele in punc:
name = name.replace(ele, " ")
print(name)
doc = nlp(name)
x = []
str = ""
for token in doc:
if token.pos_=="PROPN":
x.append(token)
for i in range(len(x)):
str += "-"
str += x[i].text
return str
url = request.form['text']
html = urllib.request.urlopen(url)
htmlParse = BeautifulSoup(html, 'html.parser')
content = ""
for para in htmlParse.find_all("p"):
content += para.get_text()
print(content)
ans = spacyFunction(content)
print(ans)
return ans
if __name__ =="__main__":
app.run(debug = True)