美女组:空条目?不再工作了?

2024-05-19 21:14:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用BeautifulSoup把xml(googlecontacts)转换成csv。我有一个完美的工作脚本,但它停止了工作,现在没有作出任何改变的来源。也许美丽的组合变了??你知道吗

因此,xml文件包含如下条目:

 <entry ns1:etag="&quot;RcDVSLt7I2AQEQAM.&quot;">
 <category scheme="http://schemas.google.com/g/..." />
 <title>Pepe Estropajo</title>
 </edited>
 <name>
 <fullName>Pepe</fullName>
 <givenName>...</givenName>
 <familyName>Estropajo</familyName>
 </name>
 </entry>

我想提取数据。所以我做了:

 for entry in soup.findAll('entry'):
 name = entry.title
 ....

问题是nameNone。为什么找不到标题? 我要求脚本打印名称,它打印了:

<entry ns1:etag='"Rng-cDVSLyt7I2A9Wh5QEEUNQAM."'></entry>

里面没有孩子。你知道吗

我做错什么了?你知道吗


Tags: name脚本titlexmletagentryfullnamebeautifulsoup
1条回答
网友
1楼 · 发布于 2024-05-19 21:14:08

你喜欢这个工作吗?你知道吗

>>> entries = """<entry ns1:etag="&quot;RcDVSLt7I2AQEQAM.&quot;">
...  <category scheme="http://schemas.google.com/g/..." />
...  <title>Pepe Estropajo</title>
...  </edited>
...  <name>
...  <fullName>Pepe</fullName>
...  <givenName>...</givenName>
...  <familyName>Estropajo</familyName>
...  </name>
...  </entry>"""
>>> 
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(entries)
>>> 
>>> for entry in soup.findAll('entry'):
...     print entry.find('title').getText()
... 
Pepe Estropajo

相关问题 更多 >