python:报废网站的字符串/列表值
我试图从以下方式构成以下方式的网站上获取值列表:
<sellableUnits>
<attributes>
<id>SIZE_1317058</id>
<type>size</type>
<value>XS</value>
</attributes>
这将为网站上所有可用的尺寸重复。
我使用以下代码:
all_sizes = []
for variants in data['sellableUnits']:
sizes = variants['attributes'][0]['value']
all_sizes.append(sizes)
all_sizes = '\n'.join(all_sizes)
我可以获取所有值,但是值列表将每个值重复4次。不知道为什么。我得到的是:
XS XS XS XS s s s s m m m m l l l l XL XL XL XL
当我得到:XS SML XL时,
任何帮助将不胜感激。
Im trying to get a list of values from a website that is structured the following way:
<sellableUnits>
<attributes>
<id>SIZE_1317058</id>
<type>size</type>
<value>XS</value>
</attributes>
This repeats itself for all the sizes available on the website.
Im using the following code:
all_sizes = []
for variants in data['sellableUnits']:
sizes = variants['attributes'][0]['value']
all_sizes.append(sizes)
all_sizes = '\n'.join(all_sizes)
I can get all the values, however the list of values repeats each value 4 times. No idea why. What i get is this:
XS
XS
XS
XS
S
S
S
S
M
M
M
M
L
L
L
L
XL
XL
XL
XL
When i should get: XS S M L XL
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我所说,
'SellableUnits'
中有多个元素具有这些尺寸。如您所见,下图中的第一个2。因此,您的代码正是要做什么应该做的。
As I was saying, there are multiple elements in the
'sellableUnits'
that have those sizes.As you can see the first 2 in the image below. So your code is doing precisely what it should be doing.