Skip to content

Instantly share code, notes, and snippets.

@melissamarima
Created August 14, 2016 16:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save melissamarima/4ce018bb5c26daff965e0d0ac228c056 to your computer and use it in GitHub Desktop.
Betfair scrape try
# 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