我正在尝试使用漂亮的汤来获取网站的数据,它的运行非常适合前4-5个查询但在此之后我收到此错误:
Description: Traceback (most recent call last):
File "./r.py", line 11, in <module>
print "Description: ",k.text
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 16: ordinal not in range(128)
这是我的代码:
#!/usr/bin/python
from bs4 import BeautifulSoup
import urllib2
response = urllib2.urlopen('http://websitename.com')
html = response.read()
soup = BeautifulSoup(html)
for i in soup.findAll("div", {"class": "ParentDiv"}):
for j in i.findAll("a",limit=1):
print "Name is: ",j.text
for k in i.findAll("div", {"class":"description"},limit=1):
print "Description: ",k.text
for l in i.findAll("div", {"class":"Information"},limit=1):
print "Addition info",l.text