Skip to content

Instantly share code, notes, and snippets.

@pkpp1233
Created December 4, 2014 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkpp1233/2c534c1bbe8a5597b031 to your computer and use it in GitHub Desktop.
Save pkpp1233/2c534c1bbe8a5597b031 to your computer and use it in GitHub Desktop.
Scraper UI
<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>
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