我对python 2.7非常陌生,并使用urilib2从URL读取数据并写入正常的txt文件,
webPage = urllib2.urlopen('https://www.somewebsite.com').read()
soup = BeautifulSoup(webPage)
urlData= open("urlData.txt","a+")
div = soup.find("div",{"class":"imgMrgnTopLG imgMrgnBtmLG listBullet"})
for row in div.findAll('ul'):
for li in row.findAll('li'):
if any( ext in li.text.encode('utf-8') for ext in keys):
urlData.write(li.text.encode('utf-8')+"\n")
执行上述代码后,我遇到此错误,我已尝试过以前的解决方案,但无法修复。请帮帮我,谢谢你。
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)