英文链接好好的,比如 www.sss.com/keyword=english
, 输出没问题
但是中文就不行了,如 www.ssss.com/keyword=中文
中文的可以 print
在运行结果里,但无法输出至 txt
程序代码:
paramFile = codecs.open('e:/Dataresult.txt', 'w', 'gb18030')
dataFile = open('E:\\new.txt')
...
page = urllib2.Request(args, headers=headers)
html = r.read()
soup = BeautifulSoup(html, 'lxml')
....
param = soup.title.a
print>>paramFile, product+'\r\n'
错误代码:
Traceback (most recent call last):
File "C:/Users/ctbri-xxx/PycharmProjects/bs/alpha0.1.py", line 213, in <module>
print>>paramFile, product+'\r\n'
File "C:\Python27\lib\codecs.py", line 706, in write
return self.writer.write(data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position 0: ordinal not in range(128)