I wrote a very small script using the class to scrape some Craigslist product titles. My intention is to make use of
__str __ () method so that my script can print the result without explicitly calling this method.
However, when I run my script in the following manner, I get the desired results.
Is this the only way I can print the result or is there something better to print the result by the str strand method?
import requests from bs4 import BeautifulSoup URL = "http://bangalore.craigslist.co.in/search/rea?s=120" DataSourcer class: def __init __ (auto, link): self.link = link self.datalist =  def fetch (auto): res = requests.get (self.link) soup = BeautifulSoup (res.text, "lxml") for ilink in soup.select ("li.result-row a[data-id]"): self.datalist.append (ilink.text) # return self.datalist #I do not want to come back "self.datalist" here def __str __ (auto): returns to the auto-natalist if __name__ == __ __ hand __: crawler = DataSourcer (URL) crawler.fetch () print (crawler .__ str __ ()) # J & # 39; found it worked that way