I have created a script to scrape football fixtures data.
The first thing I have created is the part of scraping the date and time.
See the script below:
import requests
from bs4 import BeautifulSoup
import time
from datetime import datetime,date,timedelta
check_page_nr = 37
league_id_sw = '53145'
league_name = 'Premier League'
country_name = 'England'
while True:
url = 'https://nl.soccerway.com/a/block_competition_matches_summary?block_id=page_competition_1_block_competition_matches_summary_5&callback_params={{"page":"34","block_service_id":"competition_summary_block_competitionmatchessummary","round_id":"{}","outgroup":"","view":"1","competition_id":"8"}}&action=changePage¶ms={{"page":{}}}'.format(league_id_sw, check_page_nr)
agent = {"User-Agent":'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
all_the_data = requests.get(url, headers=agent).json()
check_next = all_the_data['commands'][1]['parameters']['attributes']['has_next_page']
matcheshtml = all_the_data['commands'][0]['parameters']['content']
soup = BeautifulSoup(matcheshtml, 'html.parser')
matches = soup.select('.matches tbody tr')
for matchcontainer in matches:
date_new = ''
time_new = ''
match_datetimestamp = matchcontainer.find('span', class_='timestamp')
if match_datetimestamp.get('data-format') == 'dd/mm/yyyy':
date_new = match_datetimestamp.get_text().strip()
if match_datetimestamp.get('data-format') == 'HH:MM':
time_new = match_datetimestamp.get_text().strip()
print(date_new, time_new)
check_page_nr += 1
if not check_next: break
The ouput is:
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
(u’26/07/2020’, ‘’)
(’’, u’17:00’)
But the result is on two rows I want to print this in one row.
Like
(u’26/07/2020’, u’17:00’)
How can I fix this?