Created
December 4, 2014 20:24
-
-
Save pkpp1233/2c534c1bbe8a5597b031 to your computer and use it in GitHub Desktop.
Scraper UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<form accept-charset="UTF-8" action="/scrape" method="post"> | |
<input autofocus="autofocus" placeholder="nba" type="text" name="sport"> | |
<input type="submit" value="Get my headlines!"> | |
<br> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
from bs4 import BeautifulSoup | |
from flask import Flask, jsonify, request, render_template | |
import os | |
app = Flask(__name__, template_folder = os.path.dirname(os.path.abspath(__file__))) | |
@app.route('/') | |
def index(): | |
return render_template('index.html') | |
@app.route('/scrape', methods=["POST"]) | |
def scrape(): | |
sport = request.form['sport'] | |
html = urllib.urlopen("http://www.espn.com/" + sport).read() | |
headlines = [headline.get_text() for headline in BeautifulSoup(html).find(class_="headlines").find_all('li')] | |
return jsonify(results = headlines) | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment