简体   繁体   English

美丽的汤-嵌套表

[英]Beautiful Soup - Nested table

I am first going to point out that I am new to all of this but struggling with trying to get to a nested tables cells. 我首先要指出的是,我对这一切都是陌生的,但是在尝试获取嵌套表单元格方面却很挣扎。

Here is the square footage field I am trying to get to down around line 282: view-source: http://services.wakegov.com/realestate/Account.asp?id=0355891 这是我试图在第282行附近看到的平方英尺字段:view-source: http : //services.wakegov.com/realestate/Account.asp?id=0355891

'square_feet': soup.findAll('table')[10].findAll('tr')[15].get_text().strip(),

The error I receive is: 我收到的错误是:

IndexError: list index out of range IndexError:列表索引超出范围

一种更易读,更简单的方法是依靠参数标签-换句话说,通过文本查找元素,获取父td元素并找到下一个td兄弟元素,例如:

soup.find(text="Heated Area").find_parent('td').find_next_sibling("td").get_text() 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM