i need put content of vector/list csv. i'm getting trouble "python encoding problem" obviously.
here code we're taklin' :
import pdb #pdb.set_trace() import sys sys.version_info import csv bs4 import * import urllib.request rows=list() def parse_csv(content, delimiter = ';'): csv_data = [] line in content.split('\n'): csv_data.append( [x.strip() x in line.split( delimiter )] ) # strips spaces return csv_data list_url=parse_csv(open('url.csv','ru').read()) in range (0,len(list_url)): url=str(list_url[i][0]) ## read url array coming url-csv page=urllib.request.urlopen(url) soup = beautifulsoup(page.read(),"html.parser") h1 in soup.find_all('h1'): rows.append(h1.get_text().encode('utf-8').strip()) #looks title h2 in soup.find_all('h2'): rows.append(h2.get_text().encode('utf-8').strip()) #looks title restricted_webpage= soup.find( "div", {"id":"ingredients"} ) readable_restricted=str(restricted_webpage) soup2=beautifulsoup(readable_restricted,"html.parser") td in soup2.find_all('td'): rows.append(td.get_text().encode('utf-8').strip()) print(rows) if sys.version_info >= (3,0,0): f = open('fb.csv', 'w', newline='') else: f = open('fb.csv', 'wb') wr = csv.writer(f) wr.writerows(rows) if that. csv looks : (which not fine @ all)
65,100,117,108,116,32,83,109,97,108,108,32,68,111,103 68,101,32,112,108,117,115,32,100,101,32,56,47,32,49,48,32,109,111,105,115,46 67,101,110,100,114,101,115,32,98,114,117,116,101,115,32,40,37,41 55,46,52 67,101,108,108,117,108,111,115,101,32,98,114,117,116,101,32,40,37,41 49,46,54 70,105,98,114,101,115,32,97,108,105,109,101,110,116,97,105,114,101,115,32,40,37,41 54,46,54 77,97,116,105,195,168,114,101,32,103,114,97,115,115,101,32,40,37,41 49,54,46,48 65,99,105,100,101,32,108,105,110,111,108,195,169,105,113,117,101,32,40,37,41 51,46,49 69,110,101,114,103,105,101,32,109,195,169,116,97,98,111,108,105,115,97,98,108,101,32,40,99,97,108,99,117,108,195,169,101,32,115,101,108,111,110,32,78,82,67,56,53,41,32,40,107,99,97,108,47,107,103,41 51,54,53,50,46,53 69,110,101,114,103,105,101,32,109,195,169,116,97,98,111,108,105,115,97,98,108,101,32,40,109,101,115,117,114,195,169,101,41,32,40,107,99,97,108,47,107,103,41 51,57,48,48,46,48 72,117,109,105,100,105,116,195,169,32,40,37,41 57,46,53 69,120,116,114,97,105,116,32,110,111,110,32,97,122,111,116,195,169,32,40,37,41 52,48,46,53 79,109,195,169,103,97,32,54,32,40,37,41 51,46,49,56 80,114,111,116,195,169,105,110,101,32,98,114,117,116,101,32,40,37,41 50,53,46,48 65,109,105,100,111,110,32,40,37,41 51,53,46,53 67,104,108,111,114,101,32,40,37,41 49,46,52,51 67,117,105,118,114,101,32,40,109,103,47,107,103,41 49,53,46,48 73,111,100,101,32,40,109,103,47,107,103,41 50,46,57 70,101,114,32,40,109,103,47,107,103,41 49,54,55,46,48 77,97,110,103,97,110,195,168,115,101,32,40,109,103,47,107,103,41 54,56,46,48 90,105,110,99,32,40,109,103,47,107,103,41 50,52,50,46,48 66,105,111,116,105,110,101,32,40,109,103,47,107,103,41 51,46,49,51 67,104,111,108,105,110,101,32,40,109,103,47,107,103,41 49,54,48,48,46,48 65,99,105,100,101,32,102,111,108,105,113,117,101,32,40,109,103,47,107,103,41 49,51,46,57 86,105,116,97,109,105,110,101,32,65,32,40,85,73,47,107,103,41 51,50,48,48,48,46,48 86,105,116,97,109,105,110,101,32,66,49,32,84,104,105,97,109,105,110,101,32,40,109,103,47,107,103,41 50,55,46,53 86,105,116,97,109,105,110,101,32,66,50,32,82,105,98,111,102,108,97,118,105,110,101,32,40,109,103,47,107,103,41 52,57,46,54 86,105,116,97,109,105,110,101,32,66,51,32,78,105,97,99,105,110,101,32,40,109,103,47,107,103,41 52,57,48,46,48 86,105,116,97,109,105,110,101,32,66,53,32,65,99,105,100,101,32,112,97,110,116,111,116,104,195,169,110,105,113,117,101,32,40,109,103,47,107,103,41 49,52,55,46,56 86,105,116,97,109,105,110,101,32,66,54,32,80,121,114,105,100,111,120,105,110,101,32,40,109,103,47,107,103,41 55,55,46,49 86,105,116,97,109,105,110,101,32,67,32,40,109,103,47,107,103,41 50,48,48,46,48 86,105,116,97,109,105,110,101,32,68,51,32,40,85,73,47,107,103,41 56,48,48,46,48 86,105,116,97,109,105,110,101,32,69,32,40,109,103,47,107,103,41 54,48,48,46,48 65,114,103,105,110,105,110,101,32,40,37,41 49,46,53,51 76,117,116,195,169,105,110,101,32,40,109,103,47,107,103,41 53,46,48 77,195,169,116,104,105,111,110,105,110,101,32,67,121,115,116,105,110,101,32,40,37,41 49,46,49,56 84,97,117,114,105,110,101,32,40,109,103,47,107,103,41 50,57,48,48,46,48 66,101,97,103,108,101,32,65,100,117,108,116 66,101,97,103,108,101,32,97,100,117,108,116,101,44,32,195,160,32,112,97,114,116,105,114,32,100,101,32,49,50,32,109,111,105,115 65,99,105,100,101,32,97,114,97,99,104,105,100,111,110,105,113,117,101,32,40,37,41 48,46,48,55 67,101,110,100,114,101,115,32,98,114,117,116,101,115,32,40,37,41 54,46,49 66,105,111,116,105,110,101,32,40,109,103,47,107,103,41 50,46,57,50 70,105,98,114,101,115,32,97,108,105,109,101,110,116,97,105,114,101,115,32,40,37,41 49,49,46,48 68,76,45,109,195,169,116,104,105,111,110,105,110,101,32,40,37,41 48,46,53 69,80,65,47,68,72,65,32,40,37,41 48,46,51 77,97,116,105,195,168,114,101,32,103,114,97,115,115,101,32,40,37,41 49,50,46,48 67,101,108,108,117,108,111,115,101,32,98,114,117,116,101,32,40,37,41 51,46,55 67,104,108,111,114,117,114,101,32,100,101,32,103,108,117,99,111,115,97,109,105,110,101,32,40,109,103,47,107,103,41 52,57,53,46,48 71,108,117,99,111,115,97,109,105,110,101,32,112,108,117,115,32,99,104,111,110,100,114,111,195,175,116,105,110,101,32,40,109,103,47,107,103,41 53,48,48,46,48 76,45,99,97,114,110,105,116,105,110,101,32,40,109,103,47,107,103,41 49,48,48,46,48 65,99,105,100,101,32,108,105,110,111,108,195,169,105,113,117,101,32,40,37,41 50,46,52,50 76,117,116,195,169,105,110,101,32,40,109,103,47,107,103,41 53,46,48 69,110,101,114,103,105,101,32,109,195,169,116,97,98,111,108,105,115,97,98,108,101,32,40,99,97,108,99,117,108,195,169,101,32,115,101,108,111,110,32,78,82,67,56,53,41,32,40,107,99,97,108,47,107,103,41 51,52,50,53,46,48 69,110,101,114,103,105,101,32,109,195,169,116,97,98,111,108,105,115,97,98,108,101,32,40,109,101,115,117,114,195,169,101,41,32,40,107,99,97,108,47,107,103,41 51,53,56,52,46,48 77,195,169,116,104,105,111,110,105,110,101,32,67,121,115,116,105,110,101,32,40,37,41 48,46,57,50 72,117,109,105,100,105,116,195,169,32,40,37,41 57,46,53 69,120,116,114,97,105,116,32,110,111,110,32,97,122,111,116,195,169,32,40,37,41 52,49,46,55 79,109,195,169,103,97,32,51,32,40,37,41 48,46,54,52 79,109,195,169,103,97,32,54,32,40,37,41 50,46,54,54 80,104,111,115,112,104,111,114,101,32,40,37,41 48,46,55 80,114,111,116,195,169,105,110,101,32,98,114,117,116,101,32,40,37,41 50,55,46,48 65,109,105,100,111,110,32,40,37,41 51,52,46,52 84,97,117,114,105,110,101,32,40,109,103,47,107,103,41 51,53,48,48,46,48 86,105,116,97,109,105,110,101,32,65,32,40,85,73,47,107,103,41 50,57,48,48,48,46,48 86,105,116,97,109,105,110,101,32,67,32,40,109,103,47,107,103,41 51,48,48,46,48 86,105,116,97,109,105,110,101,32,69,32,40,109,103,47,107,103,41 54,48,48,46,48 67,97,108,99,105,117,109,32,40,37,41 48,46,57 80,111,108,121,112,104,195,169,110,111,108,115,32,100,101,32,116,104,195,169,32,118,101,114,116,32,101,116,32,100,101,32,114,97,105,115,105,110,115,32,40,109,103,47,107,103,41 49,53,48,46,48 67,104,108,111,114,101,32,40,37,41 48,46,54,51 67,117,105,118,114,101,32,40,109,103,47,107,103,41 49,53,46,48 73,111,100,101,32,40,109,103,47,107,103,41 52,46,56 70,101,114,32,40,109,103,47,107,103,41 50,49,50,46,48 77,97,103,110,195,169,115,105,117,109,32,40,37,41 48,46,48,56 77,97,110,103,97,110,195,168,115,101,32,40,109,103,47,107,103,41 55,49,46,48 80,111,116,97,115,115,105,117,109,32,40,37,41 48,46,55 83,195,169,108,195,169,110,105,117,109,32,40,109,103,47,107,103,41 48,46,50,57 83,111,100,105,117,109,32,40,37,41 48,46,52 90,105,110,99,32,40,109,103,47,107,103,41 50,48,49,46,48 67,104,111,108,105,110,101,32,40,109,103,47,107,103,41 50,50,48,48,46,48 65,99,105,100,101,32,102,111,108,105,113,117,101,32,40,109,103,47,107,103,41 49,50,46,57 86,105,116,97,109,105,110,101,32,66,49,32,84,104,105,97,109,105,110,101,32,40,109,103,47,107,103,41 50,53,46,55 48,46,49,51 86,105,116,97,109,105,110,101,32,66,50,32,82,105,98,111,102,108,97,118,105,110,101,32,40,109,103,47,107,103,41 52,54,46,50 86,105,116,97,109,105,110,101,32,66,51,32,78,105,97,99,105,110,101,32,40,109,103,47,107,103,41 52,53,56,46,55 86,105,116,97,109,105,110,101,32,66,53,32,65,99,105,100,101,32,112,97,110,116,111,116,104,195,169,110,105,113,117,101,32,40,109,103,47,107,103,41 49,51,55,46,57 86,105,116,97,109,105,110,101,32,66,54,32,80,121,114,105,100,111,120,105,110,101,32,40,109,103,47,107,103,41 55,50,46,48 86,105,116,97,109,105,110,101,32,68,51,32,40,85,73,47,107,103,41 56,48,48,46,48 65,114,103,105,110,105,110,101,32,40,37,41 49,46,53,50 76,45,108,121,115,105,110,101,32,40,37,41 49,46,48,56 74,97,99,107,32,82,117,115,115,101,108,108,32,65,100,117,108,116 7 53,46,57 66,105,111,116,105,110,101,32,40,109,103,47,107,103,41 this implies have decode csv use in future. doesn't work me. need "visual".
if try replace every
encode('utf-8').strip() by :
strip() i receive error :
wr.writerows(rows) unicodeencodeerror: 'ascii' codec can't encode character '\xe8' in position 8: ordinal not in range(128)
strip is useful here because helps me rid of '\n' don't
here second thing i've tried : rid of é'èàù% , other trouble maker turning asci 1 :
yourstring = yourstring.encode('ascii', 'ignore').decode('ascii') the results not bad not enough :
" ",a,d,u,l,t, ,s,m,a,l,l, ,d,o,g d,e, ,p,l,u,s, ,d,e, ,8,/, ,1,0, ,m,o,i,s,. " ", , , , , , , , , , , , , , , , ,c,e,n,d,r,e,s, ,b,r,u,t,e,s, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,7,.,4," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,e,l,l,u,l,o,s,e, ,b,r,u,t,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,6," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,f,i,b,r,e,s, ,a,l,i,m,e,n,t,a,i,r,e,s, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,6,.,6," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,a,t,i,r,e, ,g,r,a,s,s,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,6,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,l,i,n,o,l,i,q,u,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,.,1," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,n,e,r,g,i,e, ,m,t,a,b,o,l,i,s,a,b,l,e, ,(,c,a,l,c,u,l,e, ,s,e,l,o,n, ,n,r,c,8,5,), ,(,k,c,a,l,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,6,5,2,.,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,n,e,r,g,i,e, ,m,t,a,b,o,l,i,s,a,b,l,e, ,(,m,e,s,u,r,e,), ,(,k,c,a,l,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,9,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,h,u,m,i,d,i,t, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,9,.,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,x,t,r,a,i,t, ,n,o,n, ,a,z,o,t, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,0,.,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,o,m,g,a, ,6, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,.,1,8," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,p,r,o,t,i,n,e, ,b,r,u,t,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,m,i,d,o,n, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,5,.,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,h,l,o,r,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,4,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,u,i,v,r,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,i,o,d,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,.,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,f,e,r, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,6,7,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,a,n,g,a,n,s,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,6,8,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,z,i,n,c, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,4,2,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,b,i,o,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,.,1,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,h,o,l,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,6,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,f,o,l,i,q,u,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,3,.,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,a, ,(,u,i,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,2,0,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,1, ,t,h,i,a,m,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,7,.,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,2, ,r,i,b,o,f,l,a,v,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,9,.,6," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,3, ,n,i,a,c,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,9,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,5, ,a,c,i,d,e, ,p,a,n,t,o,t,h,n,i,q,u,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,4,7,.,8," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,6, ,p,y,r,i,d,o,x,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,7,7,.,1," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,c, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,d,3, ,(,u,i,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,8,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,6,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,r,g,i,n,i,n,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,5,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,l,u,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,t,h,i,o,n,i,n,e, ,c,y,s,t,i,n,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,1,8," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,t,a,u,r,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,9,0,0,.,0," ", , , , , , , , " ",b,e,a,g,l,e, ,a,d,u,l,t b,e,a,g,l,e, ,a,d,u,l,t,e,",", , ,p,a,r,t,i,r, ,d,e, ,1,2, ,m,o,i,s " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,a,r,a,c,h,i,d,o,n,i,q,u,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,0,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,e,n,d,r,e,s, ,b,r,u,t,e,s, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,6,.,1," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,b,i,o,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,.,9,2," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,f,i,b,r,e,s, ,a,l,i,m,e,n,t,a,i,r,e,s, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,l,i,n,o,l,i,q,u,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,.,4,2," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,l,u,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,n,e,r,g,i,e, ,m,t,a,b,o,l,i,s,a,b,l,e, ,(,c,a,l,c,u,l,e, ,s,e,l,o,n, ,n,r,c,8,5,), ,(,k,c,a,l,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,4,2,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,n,e,r,g,i,e, ,m,t,a,b,o,l,i,s,a,b,l,e, ,(,m,e,s,u,r,e,), ,(,k,c,a,l,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,5,8,4,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,t,h,i,o,n,i,n,e, ,c,y,s,t,i,n,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,9,2," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,h,u,m,i,d,i,t, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,9,.,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,x,t,r,a,i,t, ,n,o,n, ,a,z,o,t, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,1,.,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,o,m,g,a, ,3, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,6,4," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,o,m,g,a, ,6, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,.,6,6," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,p,h,o,s,p,h,o,r,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,p,r,o,t,i,n,e, ,b,r,u,t,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,7,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,m,i,d,o,n, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,4,.,4," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,t,a,u,r,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,5,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,a, ,(,u,i,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,9,0,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,c, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,6,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,a,l,c,i,u,m, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,p,o,l,y,p,h,n,o,l,s, ,d,e, ,t,h, ,v,e,r,t, ,e,t, ,d,e, ,r,a,i,s,i,n,s, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,5,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,h,l,o,r,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,6,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,u,i,v,r,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,i,o,d,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,.,8," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,f,e,r, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,1,2,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,a,g,n,s,i,u,m, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,0,8," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,a,n,g,a,n,s,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,7,1,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,p,o,t,a,s,s,i,u,m, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,s,l,n,i,u,m, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,2,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,s,o,d,i,u,m, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,4," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,z,i,n,c, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,0,1,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,h,o,l,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,2,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,f,o,l,i,q,u,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,2,.,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,1, ,t,h,i,a,m,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,5,.,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,1,2, ,c,y,a,n,o,c,o,b,a,l,a,m,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,1,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,2, ,r,i,b,o,f,l,a,v,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,6,.,2," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,3, ,n,i,a,c,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,5,8,.,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,5, ,a,c,i,d,e, ,p,a,n,t,o,t,h,n,i,q,u,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,3,7,.,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,b,6, ,p,y,r,i,d,o,x,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,7,2,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,v,i,t,a,m,i,n,e, ,d,3, ,(,u,i,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,8,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,r,g,i,n,i,n,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,5,2," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,l,-,l,y,s,i,n,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,0,8," ", , , , , , , , " ",j,a,c,k, ,r,u,s,s,e,l,l, ,a,d,u,l,t j,a,c,k, ,r,u,s,s,e,l,l, ,t,e,r,r,i,e,r, ,a,d,u,l,t,e,",", , ,p,a,r,t,i,r, ,d,e, ,1,0, ,m,o,i,s " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,a,r,a,c,h,i,d,o,n,i,q,u,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,0,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,e,n,d,r,e,s, ,b,r,u,t,e,s, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,5,.,9," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,b,i,o,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,.,0,7," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,f,i,b,r,e,s, ,a,l,i,m,e,n,t,a,i,r,e,s, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,7,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,d,l,-,m,t,h,i,o,n,i,n,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,6,5," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,p,a,/,d,h,a, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,0,.,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,m,a,t,i,r,e, ,g,r,a,s,s,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,6,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,e,l,l,u,l,o,s,e, ,b,r,u,t,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,.,3," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,c,h,l,o,r,u,r,e, ,d,e, ,g,l,u,c,o,s,a,m,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,4,9,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,g,l,u,c,o,s,a,m,i,n,e, ,p,l,u,s, ,c,h,o,n,d,r,o,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,5,0,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,l,-,c,a,r,n,i,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,1,5,0,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,a,c,i,d,e, ,l,i,n,o,l,i,q,u,e, ,(,%,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,2,.,8,8," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,l,u,t,i,n,e, ,(,m,g,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,5,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,n,e,r,g,i,e, ,m,t,a,b,o,l,i,s,a,b,l,e, ,(,c,a,l,c,u,l,e, ,s,e,l,o,n, ,n,r,c,8,5,), ,(,k,c,a,l,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,7,1,6,.,0," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,e,n,e,r,g,i,e, ,m,t,a,b,o,l,i,s,a,b,l,e, ,(,m,e,s,u,r,e,), ,(,k,c,a,l,/,k,g,)," ", , , , , , , , " ", , , , , , , , , , , , , , , , ,3,9,6,4,.,0," ", , , , , , , , when try add strip in addition. csv produced empty.
now strip produce error :
unicodeencodeerror: 'ascii' codec can't encode character '\xe8' in position 8: ordinal not in range(128)
i read , tried of stack-topic
the ascii way isn't nice because lose informations. , need them.
how can put list fb.csv ?
it looks using python 3. beautifulsoup returns unicode strings , csv takes unicode strings, don't encode them.
writerows takes list of lists of column text. looks passing list of text, strings being enumerated , giving 1 character @ time.
here's happens giving list of encoded strings csv.writerows:
>>> import csv >>> open('test.csv','w',newline='') f: ... w=csv.writer(f) ... rows = ['abc,def'.encode('utf8'),'ghi,jkl'.encode('utf8')] ... w.writerows(rows) ... >>> c:\>type test.csv 97,98,99,44,100,101,102 103,104,105,44,106,107,108 and here's happens when give list of unicode strings instead of list of lists of unicode strings. note specify encoding unicode strings, specified in open:
>>> import csv >>> open('test.csv','w',encoding='utf8',newline='') f: ... w=csv.writer(f) ... rows=['\xe8abc,def','\xe8def,ghi'] ... w.writerows(rows) ... >>> note: code page 65001 utf-8. switching displays characters correctly:
c:\>chcp 65001 active code page: 65001 c:\>type test.csv è,a,b,c,",",d,e,f è,d,e,f,",",g,h,i here's how correct output:
>>> import csv >>> open('test.csv','w',encoding='utf8',newline='') f: ... w=csv.writer(f) ... rows = [['abcd\xe8','d\xe8fg'],['ghijk','lmnop']] ... w.writerows(rows) ... >>> c:\>type test.csv abcdè,dèfg ghijk,lmnop
Comments
Post a Comment