如何在web浏览器字符串中使用Python占位符

2024-09-30 06:20:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要格式化一个字符串,并将其发送到带有splinter模块的web浏览器。 我通常使用占位符,但这次不起作用。 这是我要传递给浏览器的字符串:

http://NAMESERVER:8082/ViewObjectRes//TransactionLogManagerPostErrorHandling\%28Instance+0\%29\%3Ainstance\%3DInstance+0

其中NAMESERVER是我要连接到的服务器的fqdn。 我像往常一样尝试使用占位符,但出现了一个错误:

print ("http://%s:8082/ViewObjectRes//TransactionLogManagerPostErrorHandling\\%28Instance+0\\%29\\%3Ainstance\\%3DInstance+0" % "TEST")

TypeError: not enough arguments for format string

我想我应该避开其他的百分号,但我尝试了却没有成功。你知道吗


Tags: 模块字符串test服务器webhttp错误浏览器
1条回答
网友
1楼 · 发布于 2024-09-30 06:20:52

使用包含%的url格式可能更容易?你知道吗

print "http://{}:8082/ViewObjectRes//TransactionLogManagerPostErrorHandling\\%28Instance+0\\%29\\%3Ainstance\\%3DInstance+0".format("TEST")

相关问题 更多 >

    热门问题