python - BeautifulSoup does not parse content of the tag like first-name that contains '-' -
hi have response below
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <person> <first-name>hede</first-name> <last-name>hodo</last-name> <headline>python developer @ hede</headline> <site-standard-profile-request> <url>http://www.linkedin.com/profile/view?id=hede&authtype=godasd*</url> </site-standard-profile-request> </person> and want parse content returned linkedin api.
i using beautifulsoup below
ipdb> hede = beautifulsoup(response.content) ipdb> hede.person.headline <headline>python developer @ hede</headline> but when do
ipdb> hede.person.first-name *** nameerror: name 'name' not defined any ideas ?
python attribute names can not contain hypen. instead use
hede.person.findchild('first-name') also, parse xml beautifulsoup, use
hede = bs.beautifulsoup(content, 'xml') or if have lxml installed,
hede = bs.beautifulsoup(content, 'lxml')
Comments
Post a Comment