2016-03-01 78 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

相關問題