我需要在selenium webdriver+python中替换以下url的一部分:
https://ve-215:8443/cloudweb/dropbox_authorized?oauth_token=l8eYuFG8nux3TUHm&uid=69768040
我需要将ve-215
替换为ip地址,比如192.168.24.53
我尝试过使用replace
,但它不起作用。在
以下是我使用的代码:
current_url=driver.current_url
print(current_url) #prints the url of the current window.
current_url.replace("ve-215", "192.168.53.116")
print(current_url) #print url with replaced string
driver.get(current_url) #open window with replaced url
有谁能帮我解决上面代码的问题吗?在
replace
方法返回一个应用了修改的字符串,但不修改当前字符串。在你应该这样使用它:
replace
方法不修改字符串本身(字符串在Python中是不可变的),但返回一个新的字符串。试试看尽管如此,建议使用^{} 模块(python3中的^{} )来解析和重构url。在
相关问题 更多 >
编程相关推荐