2015-04-03 174 views
0

我有一個錯誤類型錯誤: 'NoneType' 對象不是可調用的蟒蛇

File "logins3", line 17, in <module> 
    my_inputs = soup.findall('input') 
TypeError: 'NoneType' object is not callable 

我的代碼

# extract the token 

soup = BeautifulSoup(response.content) 
my_inputs = soup.findall('input') 

for input in my_inputs: 
    print input.name + input['value'] #is here 

信息

<input type="hidden" name="return" value="ovL2FuaW1lZGlnaXRhbG5ldHdvcmsuZZXgucGhwL2Nvbm5leGlvbg==" /> 
    <input type="hidden" name="8d900dda34d7a3d37252b4a3c8" value="1" /> 

我需要這個令牌創建我的腳本我看不到如何修復它

ty

回答

1

您需要在soup.findall

my_inputs = soup.find_all('input') 

OR

>>> my_inputs = soup.findAll('input') 
>>> for in_put in my_inputs: 
     print in_put.name , in_put['value'] 


input ovL2FuaW1lZGlnaXRhbG5ldHdvcmsuZZXgucGhwL2Nvbm5leGlvbg== 
input 1 
a之前使用 _
1

這是一個錯字。

你打算使用find_all()而不是findall()


僅供參考,它並沒有失敗,AttributeError這裏,因爲在BeautifulSoup點符號有特殊的含義 - soup.findall基本上快捷方式soup.find("findall")。換句話說,它試圖找到名稱爲findall的元素,失敗並返回None。這就是你如何得到'NoneType' object is not callable

相關問題