Created
August 14, 2016 16:29
-
-
Save melissamarima/4ce018bb5c26daff965e0d0ac228c056 to your computer and use it in GitHub Desktop.
Betfair scrape try
This file contains hidden or 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