Python BeautifulSoup不会解析包含'-';
嗨,我的回答如下Python BeautifulSoup不会解析包含'-';,python,xml,beautifulsoup,Python,Xml,Beautifulsoup,嗨,我的回答如下 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <person> <first-name>hede</first-name> <last-name>hodo</last-name> <headline>Python Developer at hede</headline> <site-standard-profil
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
<first-name>hede</first-name>
<last-name>hodo</last-name>
<headline>Python Developer at hede</headline>
<site-standard-profile-request>
<url>http://www.linkedin.com/profile/view?id=hede&authType=godasd*</url>
</site-standard-profile-request>
</person>
ipdb> hede = BeautifulSoup(response.content)
ipdb> hede.person.headline
<headline>Python Developer at hede</headline>
有什么想法吗?Python属性名称不能包含hypen。 改用
hede.person.findChild('first-name')
另外,要使用BeautifulSoup解析XML,请使用
hede = bs.BeautifulSoup(content, 'xml')
或者如果您安装了lxml
hede = bs.BeautifulSoup(content, 'lxml')
BeautifulSoup是一个HTML解析器,请使用实际的XML解析器执行此任务。
hede = bs.BeautifulSoup(content, 'lxml')