Use regular expressions for this. For example:
text = """ Дискотеки Москвы: анонс на 1 ноября Дискотеки Москвы: анонс на 1 декабря Дискотеки СПб: анонс на 10 декабря Дискотеки СПб: анонс на 26 декабря """ import re for date, month in re.findall('анонс на (\d+) (\w+)', text): print(date, month)
Console:
1 ноября 1 декабря 10 декабря 26 декабря
For a single expression, you can use the search method:
text = "Дискотеки Москвы: анонс на 1 ноября" import re match = re.search('анонс на (\d+) (\w+)', text) if match: date = match.group(1) month = match.group(2) print(date, month) # 1 ноября
Ps.
Examples in Python 3. For Python 2, you need to import the function print: from __future__ import print_function , or use the print operator of the same name.