python - Print Statement into a variable -
i'm using beautifulsoup scrap image links. using coded managed them
images = [] images = page_soup.findall('img') image in images: print(image.get('src'))
now write links csv file, there way turn print statement variable write row?
here code far
with open('index.csv', 'a') csv_file: writer = csv.writer(csv_file) writer.writerow([name, images, datetime.now()])
update changed code
images = [] images = page_soup.findall('img') open('index.csv', 'a') csv_file: writer = csv.writer(csv_file) image in images: writer.writerow([image.get_text(), image.get('src'), datetime.now()])
but still having formatting issue in csv, want image links print in same row.
just refactor code use feteched data fill cvs.
like work :
images = [] images = page_soup.findall('img') open('index.csv', 'a') csv_file: writer = csv.writer(csv_file) image in images: writer.writerow([image.get_text(), image.get('src'), datetime.now()])
Comments
Post a Comment