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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -