2016-03-01 77 views
0

我试图用beautifulsoup找到从HTML列表中的所有NUM的:线= line.strip()类型错误:“NoneType”对象不是可调用

import urllib 
from BeautifulSoup import * 
import re 

line = None 
url = raw_input('Enter - ') 
html = urllib.urlopen(url).read() 

soup = BeautifulSoup(html) 

# Retrieve all of the anchor tags 
tags = soup('span') 
for line in tags: 
    line = line.strip() 
    numlist = re.findall('[0-9]+' , tags) 
print numlist` 

我得到一个回溯:

Traceback (most recent call last): File "C:\Documents and Settings\mea388\Desktop\PythonSchool\new 12.py", line 14, in line = line.strip() TypeError: 'NoneType' object is not callable

我不明白为什么我要回溯。

回答

1

这是因为您正试图在美丽的汤内的标签类上运行strip。

行更改14:

line = line.string.strip() 

但是要知道,这还是可以无当您正在搜索的标签具有多个子元素。 Seee link to string method on doco for beautiful soup

相关问题