This is my first question here, feel free to tell me if there is something I'm doing wrong. I'm trying to extract "Title" and "Show time" from a movie website for some sociological study.
My python code is working however it takes only the first index of my list named "horaire" when I would like to include them all in my csv file.
My issue is that I dont know in advance how many index will this list contain.
Find my script below :
from urllib import urlopen
from bs4 import BeautifulSoup
import csv
import sys
url = "http://www.allocine.fr/seance/salle_gen_csalle=C0116.html"
html = urlopen(url).read()
soup = BeautifulSoup(html, "lxml")
reload(sys)
sys.setdefaultencoding('utf8')
with open('test2306.csv', 'wb') as csvfile:
cinemaWriter = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
for films in soup.find_all('div',
{'class': 'card entity-card entity-card-list movie-card-theater cf hred'}):
horaire = films.find_all('span',
{'class': 'showtimes-hour-item-value'})
titres = films.find_all('a',
{'class': 'meta-title-link'})
cinemaWriter.writerow([horaire[0:].text.strip(),
titres[0:].text.strip()])
Thank you for your help <3 !
Jack