Scraping a website using Python and printing to a file conflict -
i trying scrape data website , write extracted data in file. related question here.
in answer there function:
def get_books(data): soup = beautifulsoup(data) title in soup.select("div.zg_itemimmersion div.zg_title a"): print title.get_text(strip=true)
and whole thing works great. but, add line write book title in file, see not book titles displayed on screen. if there conflict somewhere or there time sensitive function somewhere.
the code behave strangely alone line:
def get_books(data): soup = beautifulsoup(data) f = open('myfile','a') title in soup.select("div.zg_itemimmersion div.zg_title a"): print title.get_text(strip=true) f.write(title.get_text(strip=true)) f.close()
Comments
Post a Comment