2014-09-22 15 views
0

我正在努力使我的CS:GO Match Simulator自動獲取有關團隊和玩家的統計數據。爲此,我需要將「文本」變量寫入文本文件。如果有人能幫助我,那會很好。提前致謝!試圖寫一個變量到Python中的文件,我得到UnicodeEncodeError

UnicodeEncodeError: 'ASCII' 編解碼器無法編碼的字符的u '\ XF6' 在位置58743:在範圍內(128)

def find_source(pages): 
global page 
page = 1 
fw = open('source_code'+str(page)+'.txt', 'w') 
while page <= pages: 
    url = "http://www.hltv.org/?pageid=173&playerid="+str(page)+"&eventid=0&gameid=2" 
    sc = requests.get(url) 
    global text 
    text = sc.text 
    soup = BeautifulSoup(text) 
    #print (text) 
    text.encode('ascii', 'ignore') 
    for link in soup.findAll('a', {'class': 'tab_selected'}): 
     href = "http://www.hltv.org" + link.get('href') 
     title = link.string 
     #fw.write(title + '\n') 
     #fw.write(text) 
     #fw.write(href + '\n\n') 
    page += 1 
fw.close() 

find_source(1) 
+0

您應該解決您的縮進。 – Ajean 2014-09-22 23:03:04

回答

1

序數不這解決它。

​​
+0

謝謝,我到處尋找這個! – Yishud 2014-09-26 04:17:54

+0

NP。樂於幫助。如果它幫助你,請接受這個答案。 :) – jazdev 2014-09-26 15:40:49

相關問題