python:报废网站的字符串/列表值

发布于 2025-02-13 16:14:55 字数 615 浏览 1 评论 0原文

我试图从以下方式构成以下方式的网站上获取值列表:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2025-02-20 16:14:55

正如我所说,'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.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文