如BeautifulSoup文档中所述
您可以使用:
soup = BeautifulSoup(html)results = soup.findAll("td", {"valign" : "top"})
编辑:
要返回仅具有valign =“ top”属性的标签,可以检查tag
attrs属性的长度:
from BeautifulSoup import BeautifulSouphtml = '<td valign="top">.....</td> <td width="580" valign="top">.......</td> <td>.....</td>'soup = BeautifulSoup(html)results = soup.findAll("td", {"valign" : "top"})for result in results : if len(result.attrs) == 1 : print result
返回:
<td valign="top">.....</td>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)