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.

enter image description here

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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -