【发布时间】:2013-01-03 12:53:12
【问题描述】:
我试图将抓取的内容转换为列表以进行数据操作,但出现以下错误:TypeError: 'NoneType' object is not callable
#! /usr/bin/python
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
import os
import re
# Copy all of the content from the provided web page
webpage = urlopen("http://www.optionstrategist.com/calculators/free-volatility- data").read()
# Grab everything that lies between the title tags using a REGEX
preBegin = webpage.find('<pre>') # Locate the pre provided
preEnd = webpage.find('</pre>') # Locate the /pre provided
# Copy the content between the pre tags
voltable = webpage[preBegin:preEnd]
# Pass the content to the Beautiful Soup Module
raw_data = BeautifulSoup(voltable).splitline()
【问题讨论】:
-
使用HTML解析器(IIRC,有BeautifulSoup)。
-
只是意识到你已经导入了它,但你从来没有用它来提取标签,而是选择了正则表达式......
-
我在新代码中添加了。但是我在将内容转换为列表以进行数据操作时遇到问题。我得到 TypeError: 'NoneType' object is not callable。 Raw_data 是
。我以前从未遇到过这种情况。 -
我确实做到了。但我不明白。
标签: regex python-2.7 web-scraping beautifulsoup