【BeautifulSoup or sth】如何获得一个标签的描述信息?
<dd
isStop = "1" class='isStop'
matchcode="201409066001"
matchnumcn ="周六001"
starttime = "1409994000000"
endtime ="1409993820000"
isattention = "0"
hostname="北九州" guestname="福冈黄蜂"
leagueid = "533"
hostteamid = "46148"
visitteamid = "12193"
matchid="1000817"
leagueName="J2联赛"
class="league_533"
style="display: none;"
ishot="0"
>
pass</dd>
比如我想获取的是:
style="display: none;"
这个字段的none~如何获取呢?
工藤新一_4
10 years, 2 months ago
Answers
上代码:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
tag_content = """
<dd
isStop = "1" class='isStop'
matchcode="201409066001"
matchnumcn ="周六001"
starttime = "1409994000000"
endtime ="1409993820000"
isattention = "0"
hostname="北九州" guestname="福冈黄蜂"
leagueid = "533"
hostteamid = "46148"
visitteamid = "12193"
matchid="1000817"
leagueName="J2联赛"
class="league_533"
style="display: none;"
ishot="0">
pass</dd>
"""
from bs4 import BeautifulSoup
tag_soup = BeautifulSoup(tag_content)
style_str = tag_soup.dd["style"]
print style_str.split(":")[1].lstrip()[:-1]
Beautiful Soup不能直接获得“none”,不过我们能容易地得到
display: none;
,然后用python很容易处理了。
御菓子大好
answered 10 years, 2 months ago