title: Extracting data from Wikipedia to a txt file using Python
body: <p>I have implemented the following code to extract data from a Wikipedia page </p>
  
  <pre><code>import bs4
  import sys
  import requests
  
  res = requests.get('https://en.wikipedia.org/wiki/Agriculture' )
  res.raise_for_status()
  wiki = bs4.BeautifulSoup(res.text,"html.parser")
  for i in wiki.select('p'):
      print(i.getText())
  </code></pre>
  
  <p>This code extracts all the data from the page as I wanted. However I want to store this in a text file using Python but I am unable to. 
  The text file should have the name "Agriculture" (better if it is extracted from the url itself so that it can be use over multiple wiki pages). </p>