2017-03-09 3 views
0

파이썬에서 £ 값을 고칩니다. 엑셀 시트에 값을 쓰려고하면 프로세스가 중단되고 오류 다음'UnicodeEncodeError :'ascii 'codec'파이썬을 사용하여 엑셀 시트에 £ 기호를 쓰려고 할 때 오류가 발생합니다.

UnicodeEncodeError 'ASCII'코덱 U 위치 0 'xa3 \'문자를 인코딩 할 수없는 (128)

£ 기호 cmd를 프롬프트에 오류없이 인쇄되는 범위에 있지 서수. 어떤 사람들은 제 표 (파운드 기호 유무에 관계없이)에 값 (£ 1,750)을 쓸 수있는 방법을 제안 할 수 있습니까? 많은 감사 ...

import requests 
from bs4 import BeautifulSoup as soup 
import csv 


outputfilename = 'Ed_Streets2.csv' 

outputfile = open(outputfilename, 'wb') 
writer = csv.writer(outputfile) 
writer.writerow([Rateable Value]) 

url = 'https://www.saa.gov.uk/search/?SEARCHED=1&ST=&SEARCH_TERM=city+of+edinburgh%2C+EDINBURGH&ASSESSOR_ID=&SEARCH_TABLE=valuation_roll_cpsplit&PAGE=0&DISPLAY_COUNT=100&TYPE_FLAG=CP&ORDER_BY=PROPERTY_ADDRESS&H_ORDER_BY=SET+DESC&ORIGINAL_SEARCH_TERM=city+of+edinburgh&DRILL_SEARCH_TERM=BOSWALL+PARKWAY%2C+EDINBURGH&DD_TOWN=EDINBURGH&DD_STREET=BOSWALL+PARKWAY#results' 

response = session.get(url)     
html = soup(response.text, 'lxml') 
prop_link = html.find_all("a", class_="pagelink button small") 

for link in prop_link: 
    prop_url = base_url+(link["href"]) 

    response = session.get(prop_url) 
    prop = soup(response.content,"lxml") 

    RightBlockData = prop.find_all("div", class_="columns small-7 cell") 
    Rateable_Value = RightBlockData[0].get_text().strip() 

    print (Rateable_Value) 

    writer.writerow([Rateable_Value]) 
+0

Python 2 또는 3을 사용하고 있습니까? –

+0

나는 파이썬 2.7에있다 –

+0

안녕하세요 Odhran,'print Rateable_Value.original_encoding'는 당신을 어떻게 인쇄합니까? – DMPierre

답변

1

unicode 개체를 명시 적으로 바이트로 인코딩해야합니다. 그렇지 않으면 시스템이 자동으로 ascii 코덱을 사용하여 인코딩하려고 시도하며 이는 비 ASCII 문자로 실패합니다. 그래서,이 :

Rateable_Value = Rateable_Value.encode('utf8') 

writer.writerow([Rateable_Value]) 

트릭을 할해야하기 전에.

+0

이것은 엑셀 시트에서 대량으로 삭제할 수있는 시작 아이콘이긴하지만 작동했습니다. 고맙습니다 !! –