I would like to extract all the url links of soocer events in this webpage : https://www.coteur.com/cotes-foot.php
When I try one match by one using xpath it is ok, you can see it in my code below for fixture1 and fixture2. However I want to extract automatically all the soccer events so that I used a loop but it do not work. It seems that it is not possible to use a loop inside xpath fonction. How to solve this problem ?
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Firefox()
url = 'https://www.coteur.com/cotes-foot.php'
driver.get(url)
fixture1 = driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div/div/div[2]/div/table/tbody/tr[3]/td[3]/a")
print(fixture1.text)
fixture2 = driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div/div/div[2]/div/table/tbody/tr[23]/td[3]/a")
print(fixture2.text, '\n')
links = []
i = 3
while i <= 23:
fixture = driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div/div/div[2]/div/table/tbody/tr[i]/td[3]/a")
links.append(fixture)
i = i + 1
print(links)
driver.close()