【问题标题】:Scraping links for odds from nowgoal using python使用 python 从 nowgoal 中获取赔率的链接
【发布时间】:2021-01-27 06:46:49
【问题描述】:

我正在努力从Nowgoal 获得赔率。 首先,我喜欢使用 selenium 和 beautifulsoup 获取每场比赛的链接。 我不希望获得所有比赛的链接。但我会有一个输入 txt 文件,附在 Here 上,并使用所选的联赛和日期。

以下代码将初始化为输入:

#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:\Users\A100732\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

我找不到 xpath 来更改它。因此,我无法进一步运行该程序。

我正在寻求您的建议。 非常感谢您的帮助。 谢谢, 泽普。

【问题讨论】:

    标签: python-3.x selenium web-scraping xpath


    【解决方案1】:

    目标跨度。还添加了 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
    

    【讨论】:

    • 亲爱的 Chohan,非常感谢您的建议。在我初始化并单击团队排名后。我开始刮桌子。它向我显示了一个索引错误“IndexError:列表索引超出范围”。我认为这是由于此文本“QC:MAY88.COM - NHÀ CÁI HỢP PHÁP NA UY - THƯỞNG NẠP 100% - HOÀN TRẢ 100TR - HỖ T”
    • 我在下面的另一篇文章中发帖:stackoverflow.com/q/65929976/9561497
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多