漂亮的汤 - 嵌套 table
Beautiful Soup - Nested table
我首先要指出的是,我对所有这些都是新手,但在尝试访问嵌套表格单元格时遇到了困难。
这是我试图在第 282 行附近找到的平方英尺字段:查看源代码:http://services.wakegov.com/realestate/Account.asp?id=0355891
'square_feet': soup.findAll('table')[10].findAll('tr')[15].get_text().strip(),
我收到的错误是:
IndexError: list index out of range
一种更具可读性和简单的方法是依靠参数标签 - 换句话说,通过文本查找元素,获取父 td
元素并找到下一个 td
兄弟元素,例如:
soup.find(text="Heated Area").find_parent('td').find_next_sibling("td").get_text()
我首先要指出的是,我对所有这些都是新手,但在尝试访问嵌套表格单元格时遇到了困难。
这是我试图在第 282 行附近找到的平方英尺字段:查看源代码:http://services.wakegov.com/realestate/Account.asp?id=0355891
'square_feet': soup.findAll('table')[10].findAll('tr')[15].get_text().strip(),
我收到的错误是:
IndexError: list index out of range
一种更具可读性和简单的方法是依靠参数标签 - 换句话说,通过文本查找元素,获取父 td
元素并找到下一个 td
兄弟元素,例如:
soup.find(text="Heated Area").find_parent('td').find_next_sibling("td").get_text()