0

I am attempting to read the number of minutes that has passed in a football game from the betfair website. I understand that the content and text that I am attempting to read is generated by javascript, so am attempting to get it as follows:

def _get_time_elapsed_soccer(self, market_id):
    url = self._get_market_betfair_url(market_id)
    self._driver.get(url)

    try:
        time_elapsed_elem = WebDriverWait(self._driver, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, 'time-elapsed')))
        time_elapsed_txt = time_elapsed_elem.text

        print(time_elapsed_elem)
        print(time_elapsed_txt)
        print('length of string:', len(time_elapsed_txt))

    except TimeoutException:
        print('exception')
    finally:
        pass

and the url is generated by the method

def _get_market_betfair_url(self, market_id):
    try:
        event_info = self._get_event_type_from_market_id(market_id)
        event_type_name = str.lower(event_info['name'])

        # replace any spaces with hyphens
        event_type_name = event_type_name.replace(' ', '-')

        # replace soccer with football
        event_type_name = event_type_name.replace('soccer', 'football')

        # construct the url
        url = ''.join(['https://www.betfair.com/exchange/plus/', event_type_name, '/market/', str(market_id)])
        return url
    except TypeError:
        return False

the code in _get_time_elapsed_seccer prints out:

<selenium.webdriver.remote.webelement.WebElement (session="d58e0c50-9d45-11e7-a933-37f14018586f", element=":wdc:1505830903385")>
text:
length of string: 0

The web element is clearly returned, but the text that I can see on the page is not included. Once the javascript is loaded on the page the html looks like:

...
<p class="time-elapsed inplay" ng-class="{ inplay: sportsHeaderCtrl.data.event.status !== 'Finished' }">
    <!----> <!----><span ng-if="!sportsHeaderCtrl.data.moduleConfig.eventStatus[sportsHeaderCtrl.data.event.status]">25'</span>
    <!----><halftime-fulltime eventtypeid="sportsHeaderCtrl.data.event.eventTypeId" score="sportsHeaderCtrl.data.event.score" status="sportsHeaderCtrl.data.event.status"><!----></halftime-fulltime>
</p>
...

Should my python code not be able to get the text "25'" from the

tag with class-name 'time-elapsed'?

You can view an example of the a similar url that I have been using by looking on any in-game football match at https://www.betfair.com/exchange/plus/football/

The url is simply the above url with the specific market-id at the end.

In an ideal world if I could simply run the javascript function through selenium that returns the time elapsed that would be great but I am not sure if this is possible!

1
  • It looks like you get the WebElement ID and then don't make any subsequent calls to it. You'll likely need to make a subsequent call to get the element value attribute. Take a look at stackoverflow.com/questions/10251525/… Commented Sep 19, 2017 at 14:47

1 Answer 1

0

I found the answer to my question in this link Python Selenium: Finds h1 element but returns empty text string

I think the explanation there explains the issue well.

Sign up to request clarification or add additional context in comments.

1 Comment

While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.