from bs4 import BeautifulSoup import csv import urllib.request url = 'https://www.sports.ru/epl/table/' import urllib.request def get_html(url): response = urllib.request.urlopen(url) return response.read() def parse(html): soup = BeautifulSoup(html) teams = [] for row in soup.select('tbody > tr'): cols = row.select('td') teams.append({ 'Место': cols[0].text, 'Команда': [name.text for name in row.select('a[class=name]')], 'Матчи': cols[2].text, 'Выйгрыши': cols[3].text, 'Ничьи': cols[4].text, 'Поражения': cols[5].text, 'Забито': cols[6].text, 'Прорущено': cols[7].text, 'Очки': cols[8].text }) return teams def save(teams,path): with open(path,'w') as csvfile: writer = csv.wtiter(csvfile) writer.writerow(('Место','Команда','Матчи','Выйгрыши','Ничьи','Поражения','Забито','Пропущено','Очки')) for team in teams: writer.writerow((team['Место'], ', '.join(team['Команда']),team['Матчи'],team['Выйгрыши'],team['Ничьи'],team['Поражения'],team['Забито'],team['Прорущено'],team['Очки'])) def main(): teams = [] save(teams,'апл.csv') if __name__ == '__main__': main() 

35 line. I do not have much experience with the csv library.

Closed due to the fact that user207618, Sergey Gornostaev , Alexey Shimansky , Vladimir Martyanov , offsite , insolor Sep 2 '17 at 9:12 am .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - The spirit of the community, Sergey Gornostaev, Alexey Shimansky, Vladimir Martyanov, insolor
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    I do not think that this module has a wtiter method, here's a writer - it is quite possible.

    • Damn sight failed a stupid mistake. - Artem Zhiruev September