嗨,我是 Python 菜鸟,甚至更大的 BeautifulSoup 和 html 菜鸟。我下载了一个文件,其中包含一个 html 表。在我见过的所有 BeautifulSoup 解析示例中,它们都使用 urllib 访问表 url,然后读取响应并将其传递给 BeautifulSoup 进行解析。我的问题是,对于本地存储的文件,我是否必须将整个文件加载到内存中?所以不要说:
contenturl = "http://www.bank.gov.ua/control/en/curmetal/detail/currency?period=daily"
soup = BeautifulSoup(urllib2.urlopen(contenturl).read())
我是否改为:
soup = BeautifulSoup(open('/home/dir/filename').read())
这似乎真的行不通。所以我收到以下错误:
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
TypeError: 'module' object is not callable
如果我正在做的事情真的很愚蠢,我深表歉意,但感谢您的帮助
更新:问题已解决,需要从 BeautifulSoup 模块导入类。谢谢!