Created
August 14, 2016 16:29
Star
You must be signed in to star a gist
Betfair scrape try
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
# scrape.py | |
from bs4 import BeautifulSoup | |
import requests | |
import urllib | |
from models import Greeting | |
from models import Betfair | |
def scrapeBetfair(): | |
url = "https://www.betfair.com/exchange/politics/market?id=924.8325569&exp=e" | |
htmlcode = BeautifulSoup(urllib.urlopen(url).read(), "html.parser") | |
# finds the last <script> content, which is what we need | |
# the encode() changes unicode to str | |
roughchunk = htmlcode.find_all("script")[-1].get_text().encode('utf-8') | |
# targetstring is everything before 'Ted Cruz' | |
targetstring = roughchunk.split("Ted Cruz")[0] | |
#return targetstring | |
betfair = Betfair() | |
betfair.datatext = targetstring | |
betfair.save() | |
scrapeBetfair() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment