求大佬看看format函数报错咋回事
url = 'https://m.sheup.net/m/info_tiku_2.php?page=%d&search_key=%B4%BA%BD%DA'for pagenum in range(1,3):
new_url = format(url%pagenum)
print(new_url)
报错: new_url = format(url%pagenum)
TypeError: not enough arguments for format string
咋回事,改不对呀
本帖最后由 °蓝鲤歌蓝 于 2021-1-31 22:49 编辑
url = 'https://m.sheup.net/m/info_tiku_2.php?page=%d&search_key=%B4%BA%BD%DA'
不止一个占位符
后面的 % 要用 %% 本帖最后由 永恒的蓝色梦想 于 2021-1-31 22:20 编辑
for pagenum in range(1,3):
print(f'https://m.sheup.net/m/info_tiku_2.php?page={pagenum}&search_key=%B4%BA%BD%DA') url = 'https://m.sheup.net/m/info_tiku_2.php?page={}&search_key=%B4%BA%BD%DA'
for pagenum in range(1,3):
new_url = url.format(pagenum)
print(new_url)
==========
format函数具体用法可以看菜鸟教程:
https://www.runoob.com/python/att-string-format.html 后面的%需要转义 大概是%%代表%
页:
[1]