我是使用Python 3.8.3编程的新手。
我喜欢足球,喜欢研究各个联赛的赔率。我正在尝试从oddsportal.com网站上推断出几率,然后将其转移到excel。
我的问题是两个:
这是我的代码:
import urllib
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.common.keys import Keys
import matplotlib.pyplot as plt
import numpy as np
import openpyxl
driver=webdriver.Chrome(executable_path="C:\webdrivers\chromedriver.exe") #choose the webdriver location (chrome)
driver.get("https://www.oddsportal.com/soccer/germany/bundesliga/") # comics url
driver.find_element_by_xpath('//*[@id="tournamentTable"]/tbody/tr[4]/td[2]/a[2]').click()
print('Bookmaker', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[1]/div/a[2]').text)
print('Match', driver.find_element_by_xpath('//*[@id="col-content"]/h1').text)
print('Data', driver.find_element_by_xpath('//*[@id="col-content"]/p[1]').text)
print('1', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[2]').text)
print('X', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[3]').text)
print('2', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[4]').text)
print("=========")
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[2]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds Home[1]', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[3]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds Net[X]', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody/tr[1]/td[4]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds Away[2]', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)
print("=========")
driver.find_element_by_xpath('//*[@id="bettype-tabs"]/ul/li[8]/a/span').click()
time.sleep(1)
print('Doppia Chance', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[2]/td[1]/div/a[2]').text)
print('1X', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[2]/td[2]').text)
print('12', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[2]/td[3]').text)
print('X2', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[2]/td[4]').text)
print("=========")
driver.find_element_by_xpath('//*[@id="bettype-tabs"]/ul/li[5]/a/span').click()
time.sleep(2)
driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[4]/div/span[5]/a').click()
time.sleep(1)
print('Over 1,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[4]/table/tbody/tr[1]/td[1]/div/a[2]').text)
print('Under/Over', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[4]/table/tbody/tr[1]/td[2]').text)
print('Over 1,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[4]/table/tbody/tr[1]/td[3]').text)
print('Under 1,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[4]/table/tbody/tr[1]/td[4]').text)
print("=========")
driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/div/span[5]/a').click()
time.sleep(1)
print('Over 2,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/table/tbody/tr[1]/td[1]/div/a[2]').text)
print('Under/Over', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/table/tbody/tr[1]/td[2]').text)
print('Over 2,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/table/tbody/tr[1]/td[3]').text)
print('Under 2,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/table/tbody/tr[1]/td[4]').text)
print("=========")
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/table/tbody/tr[1]/td[3]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds Over 2,5', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[8]/table/tbody/tr[1]/td[4]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds Under 2,5', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)
print("=========")
driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[15]/div/span[5]/a').click()
time.sleep(1)
print('Over 3,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[15]/table/tbody/tr[1]/td[1]/div/a[2]').text)
print('Under/Over', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[15]/table/tbody/tr[1]/td[2]').text)
print('Over 3,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[15]/table/tbody/tr[1]/td[3]').text)
print('Under 3,5', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[15]/table/tbody/tr[1]/td[4]').text)
print("=========")
driver.find_element_by_xpath('//*[@id="tab-sport-others"]/span').click()
driver.find_element_by_xpath('//*[@id="bettype-tabs"]/ul/li[14]/div/div/p/a[3]').click()
time.sleep(1)
print('Both Teams Scores', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[1]/td[1]/div/a[2]').text)
print('Goal', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[1]/td[2]').text)
print('Nogoal', driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[1]/td[2]').text)
print("=========")
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[1]/td[2]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds Goal', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)
element=driver.find_element_by_xpath('//*[@id="odds-data-table"]/div/table/tbody/tr[1]/td[3]/a')
hover=ActionChains(driver).move_to_element(element)
hover.perform()
print('opening Odds NoGoal', driver.find_element_by_xpath('//*[@id="tooltipdiv"]').text)