【发布时间】:2013-11-24 12:12:25
【问题描述】:
我想编写一个从站点内容创建 html 文件的简单代码。我正在使用beautifulsoup 4 库。当创建 BeautifulSoup 对象时:
BeautifulSoup('<html></html>')
我收到此错误:
语法无效(init.py,第 175 行)
这行出错了:
从 bs4 导入 BeautifulSoup
我通过执行setup.py安装了库。
有什么问题?
我的整个代码:
import urllib.request as req
from bs4 import BeautifulSoup
def main():
get_announcements("92-93", 1, 153, 12)
def get_announcements(year, term, courseID, group):
website = req.urlopen('http://ce.sharif.edu/courses/' + year + '/' + str(term) + '/ce' + str(courseID) + '-' + str(group) + '/')
site_content = website.readall()
soup = BeautifulSoup('<html></html>')
if __name__ == '__main__':
main()
和库文件中 init.py 中的错误行:
try:
is_file = os.path.exists(possible_filename)
except Exception, e: #ERROR!!
# This is almost certainly a problem involving
# characters not valid in filenames on this
# system. Just let it go.
pass
【问题讨论】:
-
能否也提供第 174 行?
-
还应该有一个抑扬符指向出现错误的行中的点:请始终复制并粘贴完整的确切错误,而不是解释它。很可能,尽管您之前的行上有一个未闭合的括号。
-
@Duncan 确切的错误就是我上面所说的。请看编辑部分
-
@0xc0de:请看编辑部分
-
我在您编辑后恢复了我的 -1,但您仍然可以通过复制粘贴错误使其更清晰(并且更容易获得解决方案)。您还可以将行号添加到已编辑的部分。新添加的部分似乎并没有引发任何错误,因为它掩盖了 all 错误!您确定错误来自此文件/模块吗?
标签: python beautifulsoup syntax-error python-import