我使用BeautifulSoup
解析通過html並試圖檢索標題。BeautifulSoup獲得標題返回'NoneType'對象沒有屬性'__getitem__'
我的代碼如下:
callerid = cell_list[0]
print callerid.find('a')
,返回的我想從我的提取「標題」適當的錨標記。
<a class="caller_ref" href="/tomasi/cardio/vgh/SPsdeGBHH"
title="CDS1255S56d">identifier</a>
現在,這裏是它變得時髦。當我加入[「標題」]我的print語句來提取標題,
callerid = cell_list[0]
print callerid.find('a')["title"]
我得到
AttributeError: 'NoneType' object has no attribute 'find'
這怎麼能是「NoneType」時,它顯然包含了錨標記HTML如第一個例子所示,我如何解析它以返回標題?
你可以在'callerid = cell_list [0]'後面加上'print callerid'並顯示結果嗎? – kvorobiev
添加'[「標題」]'不會導致此錯誤。錯誤發生是因爲'callerid'是'None'。 – kindall
@kvorobiev是肯定的結果是 '