Skip to main content
 首页 » 编程设计

python之这个简单的 Python 文件中的语法错误是什么

2025年05月04日19zengkefu

按照 Tuts+ 上的 Python 教程,我在下面的代码中遇到语法错误:

#!/usr/bin/env python 
 
from bs4 import BeautifulSoup 
from urllib import urlopen 
 
html = urlopen('http://www.brainyquote.com/quotes/topics/topic_life.html').read() 
 
soup = BeautifulSoup(html) 
for section in soup.findAll('span',{"class":"bqQuoteLink"}) 
    print section 
    break 

教程要求我下载并安装BeautifulSoup ,我没有出错。我唯一能想到的是,我使用的是 4.3,而教程作者使用的是 4.1?

请您参考如下方法:

试试这个:

for section in soup.findAll('span', {"class":"bqQuoteLink"}): 

...您忘记了循环末尾的 :。