【问题标题】:Change url formatting in Jupyter Python在 Jupyter Python 中更改 url 格式
【发布时间】:2022-01-23 11:13:17
【问题描述】:

嘿,我想改变一个字符串的两个部分,第一个是最后一个字符,第二个在字符串的中间:

*nkw= 将是 cat: "sport , elec..."

*pgn= 1 , 2, 3, 4 ....

有 2 个循环,因为我想在第一只猫上运行,1...n 页,而不是继续下一个 cat - 1...n 页。

谢谢!

url_template='https://www.ebay.com/sch/i.html?_nkw=&_pgn='
categories = ["Sport","Electronics","Fashion","Health"]

for cat in categories:
for count in range(0,2):
    url = url_template%(cat,count)
    print(url)
    products = get_index_data(get_page(url))

TypeError:字符串格式化期间并非所有参数都转换了 *也试过:(cat,(str)count)

【问题讨论】:

    标签: python python-3.x string python-2.7 typeerror


    【解决方案1】:

    您需要为此使用 printf 样式的格式字符串。请参阅the documentation 了解更多信息。

    url_template='https://www.ebay.com/sch/i.html?_nkw=%s&_pgn=%d'
    

    【讨论】:

      猜你喜欢
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2023-03-26
      • 1970-01-01
      • 2023-02-22
      • 2017-01-30
      相关资源
      最近更新 更多