mardi 10 décembre 2019

how to assign a variable to each line from a repeating text pattern in python?

I have a python scrapping script to get infos about some upcomming concerts and it's the same text pattern everytime no matter how many concerts will appear, it means that each line will always be referring to a certain information such as this example (please note that there are no spaces between concerts, my data is exactly in this format):

01/01/99 9PM
Iron Maiden
Madison Square Garden 
New York City
01/01/99 9.30PM
The Doors
Staples Center
Los Angeles
01/02/99 8.45PM
Dr Dre & Snoop Dogg
Staples Center
Los Angeles
01/02/99 9PM
Diana Ross
City Hall
New York City ect...

For each line I need to assign it to a variable, so 4 variables in total:

time = all the 1st lines
name = all the 2nd lines
location = all the 3rd lines
city = all the 4th lines

Then loop through all the lines to catch the informations corresponding to each variables, such as getting all the dates from the 1st lines, all the names from the 2nd lines ect...

so far I haven't found any solutions yet, and I barely know anything about regex

I hope that you see the idea, don't hesitate if you have any questions thanks

Aucun commentaire:

Enregistrer un commentaire