为了账号安全,请及时绑定邮箱和手机立即绑定

如何将列表中的每个值附加到 url 并每次生成新的 url

如何将列表中的每个值附加到 url 并每次生成新的 url

慕运维8079593 2022-05-11 14:46:34
我正在尝试调用列表中的每个值并将其附加到 url 并每次为附加值生成 url这是我的代码    myList = ['10026','10067','10093','10117','10132','10133','10464','10524','10654','10657','10658','10701','10809','10966','11153','11173','11327','11453','11470','11478','11488','11490','12733','12750','12754','12785','13053','13683','13895','14347','14420','14438','14452','14453','14457','14460','14755','16913','17460','17497','17500','17502','18007','18013','18058','18265','18711','18778','18779','18782','18913','19790','20105','20363','20609','20766','20770','21212','21216','21262','21471','21520','21555','21833','21946','21961','22115','22203','22994','23457','23800','24260','24590','25155','25649','25749','26021','26022']    for i in myList:        unspsc_link = f"https://order.besse.com/Orders/Search/ProductSearch?query={i}"它只取最后一个值      unspsc_link    'https://order.besse.com/Orders/Search/ProductSearch?query=26022'
查看完整描述

2 回答

?
缥缈止盈

TA贡献2041条经验 获得超4个赞

你可以这样做


my_list = ['10026','10067','10093','10117','10132','10133','10464','10524','10654','10657','10658','10701','10809','10966','11153','11173','11327','11453','11470','11478','11488','11490','12733','12750','12754','12785','13053','13683','13895','14347','14420','14438','14452','14453','14457','14460','14755','16913','17460','17497','17500','17502','18007','18013','18058','18265','18711','18778','18779','18782','18913','19790','20105','20363','20609','20766','20770','21212','21216','21262','21471','21520','21555','21833','21946','21961','22115','22203','22994','23457','23800','24260','24590','25155','25649','25749','26021','26022']


unspsc_links = [f"https://order.besse.com/Orders/Search/ProductSearch?query={i}" for i in my_list]



查看完整回答
反对 回复 2022-05-11
?
慕哥6287543

TA贡献1831条经验 获得超10个赞

由于您只有一个名为 的变量,unspsc_link因此对于循环的每次迭代,它都会被覆盖。相反,您可以使用生成的 URL 创建一个新列表:


myList = ['10026','10067','10093','10117','10132','10133','10464','10524','10654','10657','10658','10701','10809','10966','11153','11173','11327','11453','11470','11478','11488','11490','12733','12750','12754','12785','13053','13683','13895','14347','14420','14438','14452','14453','14457','14460','14755','16913','17460','17497','17500','17502','18007','18013','18058','18265','18711','18778','18779','18782','18913','19790','20105','20363','20609','20766','20770','21212','21216','21262','21471','21520','21555','21833','21946','21961','22115','22203','22994','23457','23800','24260','24590','25155','25649','25749','26021','26022']

unspsc_link = []

for i in myList:

    unspsc_link.append(f"https://order.besse.com/Orders/Search/ProductSearch?query={i}")

这将生成一个包含所有所需 URL 的列表。


查看完整回答
反对 回复 2022-05-11
  • 2 回答
  • 0 关注
  • 94 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信