python tennis_result.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python tennis_result.py相关的知识,希望对你有一定的参考价值。

from selenium import webdriver
import lxml.html
import re

try:
    driver = webdriver.Firefox()
    driver.get("http://www.oddsportal.com/matches/tennis/20170205/")
    xhtml = lxml.html.fromstring(driver.page_source)
    docs = xhtml.xpath('//*[@id="table-matches"]//tr')
    for i in docs:
        children = i.getchildren()
        datas = list(map(lambda x: x.text_content(), children))
        if re.search(r'^[0-9]:[0-9]$', datas[2]):
            try:
                sets = datas[2].split(':')
                if sets[0] > sets[1]:
                    winner = datas[3]
                elif sets[0] < sets[1]:
                    winner = datas[4]
                else:
                    winner = 'unknown'
                print("%s %s (%s|%s)" % (winner, datas[3], datas[4]))
            except:
                pass
finally:
    driver.close()
    driver.quit()

以上是关于python tennis_result.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python