i know how to write multiple lines to a file, if I know how many I want to write. But, the problem comes when I want to write multiple lines, but, I don't know how much they will be
I am working on an app which scraps from a website and stores the links of the result in a text file. But, we don't know how many lines will it reply with. My code is as follows right now.
r = requests.get('http://www.crunchyroll.com/i-cant-understand-what-my-husband-is-saying')
soup = BeautifulSoup(r.text)
print soup.title
subtitles = soup.findAll('div',{'class':'wrapper container-shadow hover-classes'})
for episode in subtitles:
x = episode.find_all('a')
for a in x:
#print a['href']
z = a['href']
l = 'http://www.crunchyroll.com'+ z
print l
This gives me the desired output.So,I tried to write stuff up in a file by adding :
file = open("BatchLinks.txt", "w")
file.write(l)
file.close()
But, unfortunately, it only writes the first link. How can I add other links too?