使用Python从nowgoal抓取赔率链接



我正在努力从Nowgoal获得赔率。首先,我喜欢使用Selenium和Beautiful Soup获得每个匹配的链接。我不希望得到链接为所有的比赛。但我将有一个输入文本文件,它是附加在这里,并使用选定的联赛和日期。

以下代码将初始化为输入:
#Intialisation
league_index =[]
final_list = []
j = 0
#config load
config = RawConfigParser()
configFilePath = r'.config.txt'
config.read(configFilePath)
date = config.get('database_config','date')                     #input file provided by user - provide in YYYY-MM-DD format
leagues = config.get('database_config','leagues')               #input file provided by user - provide in windows format
headless_param =config.get('database_config','headless')        #Headless param - set True if you want to see bowser operating in foreground!
leagues_list = leagues.split(',')
print(leagues_list)

在我用首选日期和联赛初始化之后,我将设置chrome驱动程序如下:

options = webdriver.ChromeOptions()         #initialise webdriver options
#options.binary_location = brave_path        #if you are running the script on brave - then enable it
if headless_param == 'True' :
print('headless')
options.headless = True                 # if headeless parameter is set to true - the chrome browser will not appear in foreground
options.add_argument('start-maximized')     # Start the chrome maximised 
options.add_argument('disable-infobars')    # Disable infobars
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("prefs", {"profile.default_content_setting_values.cookies": 2})
options.add_experimental_option("prefs", {"profile.block_third_party_cookies": True})
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--incognito")         #Incognito mode

#intiate the driver
driver = webdriver.Chrome(resource_path('./drivers/chromedriver.exe'),options=options) 
#Format the url
url =  'http://www.nowgoal3.com/football/fixture/?f=ft0&date='+date

#get the url
driver.get(url)
#wait for some time
time.sleep(3)
driver.find_element_by_xpath('//*[@id="li_league"]').click()
time.sleep(5)
#click on the -team ranking
driver.find_element_by_xpath('//*[@id="TeamOrderCheck"]').click()

在我运行以上代码之后,我有以下错误:

> driver.find_element_by_xpath('//*[@id="TeamOrderCheck"]').click() 
File "C:UsersA100732AppDataLocalContinuumanaconda3libsite-packagesseleniumwebdriverremoteerrorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

我找不到xpath来更改它。因此,我无法进一步运行该程序。接下来我可以尝试什么?

瞄准跨度。还增加了webdriver等待,使其更稳定,而不是time.sleep()。

wait = WebDriverWait(driver,3)
#wait for some time
wait.until(EC.element_to_be_clickable((By.ID, "li_league"))).click()
#click on the -team ranking
wait.until(EC.element_to_be_clickable((By.XPATH, "//label[@for='TeamOrderCheck']/span"))).click()

进口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

最新更新