1

我正在运行一个 python 脚本。我收到一个无法解释的语法错误for。这是代码:

today = datetime.date.today()
url="http://www.99acres.com/property-in-velachery-chennai-south-ffid?"
print "INSERT INTO Property (URL,Rooms, Place, Phonenumber1,Phonenumber2,Phonenumber3,Typeofperson, Name)"
print "VALUES ("

page=urllib2.urlopen(url)
    soup = BeautifulSoup(page.read())
    properties = soup.findAll(('a', {'title':re.compile('Bedroom')}),('i',{'class':'pdate'})
    for eachproperty in properties:
     print today,","+ "http:/" + eachproperty['href'] ",", eachproperty.string"," ,.join(re.findall("'([a-zA-Z0-9,\s]*)'", eachproperty['onclick'])) 
     print ")"

错误是

$ python properties.py
  File "properties.py", line 15
    for eachproperty in properties:
                                  ^
SyntaxError: invalid syntax

更新

以下行正确吗?

properties = soup.findAll(('a', {'title':re.compile('Bedroom')}),('i',{'class':'pdate'}))
4

1 回答 1

1

与右括号的数量相比,一行的左括号计数不正确:(

properties = soup.findAll(('a', {'title':re.compile('Bedroom')}),('i',{'class':'pdate'})
#                      --^^                     ---^      ---^-^-^                -----^

再添加一个关闭)

properties = soup.findAll(('a', {'title':re.compile('Bedroom')}),('i',{'class':'pdate'}))
于 2013-09-05T10:11:49.680 回答