Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python BeautifulSoup不会解析包含'-';_Python_Xml_Beautifulsoup - Fatal编程技术网

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&amp;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')