报错如下:global name 'score' is not defined
代码如下:
for item in soup.findAll('div', {'class': 'comment-item'}):
print i
f=open('/users/xuye/desktop/json1/json{}.json'.format(j),'a')
global f
for comment in item.findAll('p'):
global desc
desc = comment.text
# print(desc)
# get comment
for rating in item.findAll('span', {'class': 'rating'}):
global score
score = str(int(rating['class'][0][7:]) / 10)
# print(score)
date = {
'score':score,
'comment':desc
}
全局变量没有定义;在循环外定义一个score变量就解决了
score = ''
for item in soup.findAll('div', {'class': 'comment-item'}):
print i
·
·
·
网友评论