我在python中抓取一个£值,当我试图把它写到excel表中时,这个过程中断了,我得到了以下错误
UnicodeEncodeError:“ascii”编解码器无法对位置0中的字符u'\xa3'进行编码:序号不在范围内(128)
在cmd提示符中,$符号正在打印,没有任何错误。有人能建议我如何把价值(1750英镑)写进我的表格(有或没有英镑符号)。非常感谢。。。在
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])
您需要将
unicode
对象明确地编码为字节。否则,您的系统将自动尝试使用ascii
编解码器对其进行编码,这将以非ascii字符失败。所以,这个:在你面前
^{pr2}$应该会成功的。在
相关问题 更多 >
编程相关推荐