-2
Я столкнулся с некоторыми проблемами, когда выполнял задания.Data mining с Python
import re
fconn=open('reviews.html')
html=fconn.read()#read the entire html into this variable
fconn.close()
#find all the matches of the given expression
matches=re.finditer('<div id="R.*?" class="a-section review".*?\
<span class="a-icon-alt">(.*?) out of 5 stars</span>.*?\
<a class="a-size-base a-link-normal review-title a-color-base a-text-bold" href="/gp/.*?>(.*?)</a>.*?\
<a class="a-size-base a-link-normal author" href="/gp/.*?>(.*?)</a>.*?\
<span class="a-size-base a-color-secondary review-date">(.*?)</span>.*?',html)
matches2=re.finditer(('<div id="R.*?" class="a-section review".*?\
<span class="a-icon-alt">(.*?) out of 5 stars</span>.*?\
<a class="a-size-base a-link-normal review-title a-color-base a-text-bold" href="/gp/.*?>(.*?)</a>.*?\
<a class="a-size-base a-link-normal author" href="/gp/.*?>(.*?)</a>.*?\
<span class="a-size-base a-color-secondary review-date">(.*?)</span>.*?\
<span class="a-size-mini a-color-state a-text-bold">(.*?)</span>.*?',html)
for M in matches:
stars=M.group(1)
title=M.group(2)
user=M.group(3)
date=M.group(4)
print stars,title,user,date
for M2 in matches2:
stars=M.group(1)
title=M.group(2)
user=M.group(3)
date=M.group(4)
purchase=M.group(5)
print stars,title,user,date,purchase
Проблема заключается SyntaxError: invalid syntax
Тогда я узнал, что, когда есть только один матч в этой программе нет такой проблемы нет. Так может кто-нибудь сказать мне, как справиться с этим? Спасибо