gpt4 book ai didi

python - python中for行的语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:45 25 4
gpt4 key购买 nike

我正在运行一个 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'}))

最佳答案

前一行的左括号数与右括号数相比不正确:

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

再添加一个结束 ):

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

关于python - python中for行的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18633447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com