ниже - код, который я использую
with open ('Argentinie1Form.txt', 'w', encoding='utf-8') as r:
driver = webdriver.Chrome("C:/Users/gdebr/Desktop/chromedriver.exe")
driver.get("https://int.soccerway.com/national/argentina/primera-division/20182019/regular-season/r47779/")
wait = WebDriverWait(driver, 10)
elm = wait.until(EC.presence_of_element_located((By.XPATH,"""//*[@id="page_competition_1_block_competition_tables_7_1_4"]""")))
elm.click()
time.sleep(2)
with open ('Argentinie1Form.txt', 'a', encoding='utf-8') as r:
teams_list = driver.find_elements_by_xpath("//table[contains(@id, 'page_competition_1_block_competition_tables_7_block_competition_form_table_1_table')]/tbody/tr/td[3]/a[1]")
for items in teams_list:
r.write(items.get_attribute('title')+'\n')
MatchesPlayed_list = driver.find_elements_by_xpath("//table[contains(@id, 'page_competition_1_block_competition_tables_7_block_competition_form_table_1_table')]/tbody/tr/td[4]")
for matches in MatchesPlayed_list:
r.write(matches.text+'\n')
Выход, который я получаю:
Но на самом деле я хочу что-то вроде этого: Racing Club, 5 и ниже этой следующей команды, и это число
Что я здесь делаю?
создал один fucntion concat_func
и определил 2 пустых списка, в которых я добавляю данные, а затем объединяю их в один
например
a = ['x', 'z']
b = ['y', 'w']
concat_func = lambda x, y: str(x) + "," + str(y)
# then
output = list(map(concat_func, a, b))
# output would be ['x,y', 'z,w']
попробуй это:
driver = webdriver.Chrome("C:/Users/gdebr/Desktop/chromedriver.exe")
driver.get("https://int.soccerway.com/national/argentina/primera-division/20182019/regular-season/r47779/")
wait = WebDriverWait(driver, 10)
elm = wait.until(EC.presence_of_element_located((By.XPATH,"""//*[@id="page_competition_1_block_competition_tables_7_1_4"]""")))
elm.click()
time.sleep(2)
concat_func = lambda x, y: str(x) + "," + str(y)
with open ('Argentinie1Form.txt', 'a', encoding='utf-8') as r:
teams_list_append = []
MatchesPlayed_list_append = []
teams_list = driver.find_elements_by_xpath("//table[contains(@id, 'page_competition_1_block_competition_tables_7_block_competition_form_table_1_table')]/tbody/tr/td[3]/a[1]")
for items in teams_list:
teams_list_append.append(items.get_attribute('title'))
# r.write(items.get_attribute('title')+'\n')
MatchesPlayed_list = driver.find_elements_by_xpath("//table[contains(@id, 'page_competition_1_block_competition_tables_7_block_competition_form_table_1_table')]/tbody/tr/td[4]")
for matches in MatchesPlayed_list:
MatchesPlayed_list_append.append(matches.text)
# r.write(matches.text+'\n')
output = list(map(concat_func, teams_list_append, MatchesPlayed_list_append))
for i in output:
r.write(i + '\n')