希望有人能帮上忙。
打印(lst_rooms.text)正常工作。
打印(lst_bed.text,lst_bath.text)结果...文本:“”NoneType“”对象没有属性“”text“”
谢谢。
。
soup=BeautifulSoup(result, 'lxml')
for lst_rooms in soup.find_all('li', class_='lst-rooms'):
lst_bed = lst_rooms.find('span', class_='lst-bed')
lst_bath = lst_rooms.find('span', class_='lst-bath')
print(lst_rooms.text)
print(lst_bath.text)
print(lst_bed.text)
result
-------
<li class="lst-rooms"><span class="bed" title="3 Beds">3 <i class="pg-icon pgicon-bedroom"></i></span> <span class="bath" title="2 Baths">2 <i class="pg-icon pgicon-shower"></i></span></li>
<li class="lst-rooms"><span class="bed" title="2 Beds">2 <i class="pg-icon pgicon-bedroom"></i></span> <span class="bath" title="2 Baths">2 <i class="pg-icon pgicon-shower"></i></span></li>发布于 2018-06-26 09:57:04
我打赌它会返回None,因为它找不到任何与你的参数匹配的东西。话虽如此,我确实注意到您正在寻找具有class: lst-bed的跨度,但在您给出的示例代码中,列表选项显示了具有class bed的跨度。
我假设,如果您相应地更改class参数,您将会找到您想要的结果。
https://stackoverflow.com/questions/51033816
复制相似问题