-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
37 lines (25 loc) · 902 Bytes
/
app.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
import json
from flask import Flask, request
from util import HeadlessBrowser
from util import extractFromHTMLHandler
app = Flask(__name__)
@app.route('/')
def home():
return """USAGE: \n\t[GET] /url : returns readability content by loading given URL on a browser.\n
\t[GET] /html: returns readability content by parsing through given HTML body.\n"""
@app.route('/html', methods=['GET'])
def extractFromHTML():
return extractFromHTMLHandler(json.loads(request.data)['HTML'])
@app.route('/url', methods=['GET'])
def extractFromURL():
"""Extract HTML content from given URL.
Returns:
json: HTML content
"""
url = json.loads(request.data)['URL']
with HeadlessBrowser(url) as browser:
readability_content = browser.fetchContent()
return readability_content
if __name__ == '__main__':
app.debug = True
app.run()