【发布时间】: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