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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -