title: How do i get my Beautiful soup output data to a text file?
body: <p>How do i get my Beautiful soup output data to a text file?<br>
  Here's the code;    </p>
  
  <pre><code>import urllib2
  
  from bs4 import BeautifulSoup
  
  url = urllib2.urlopen("http://link").read()
  
  soup = BeautifulSoup(url)
  
  file = open("parseddata.txt", "wb")
  
  for line in soup.find_all('a', attrs={'class': 'book-title-link'}):
  
   print (line.get('href'))
  
   file.write(line.get('href'))
  
   file.flush()
  
   file.close()
  </code></pre>