【发布时间】:2013-09-09 02:49:48
【问题描述】:
我正在运行一个 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'}))
【问题讨论】:
-
统计上一行
)和(的个数。 -
@AshwiniChaudhary 我已经更新了这个问题,还有一个疑问。因为,没有显示错误。但也没有输出
标签: python beautifulsoup screen-scraping