2016-04-19 9 views
2

でURLの一部を置き換えます。私はセレンwebdriverを+ pythonで次のURLの一部を交換する必要があるのpython

https://ve-215:8443/cloudweb/dropbox_authorized?oauth_token=l8eYuFG8nux3TUHm&uid=69768040私はIPアドレスにve-215を交換する必要が

が言う192.168.24.53

I 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 

誰もが上記のコードが間違っている何で私を助けることができますか?

答えて

2

replaceメソッドは文字列自体を変更しません(文字列はPythonでは不変です)が、新しい文字列を返します。言われ、URLを解析し、再構築するためurlparseモジュール(Pythonの3 urllib.parse)を使用することが推奨されていることを

current_url = current_url.replace("ve-215", "192.168.53.116") 

を試みます。

1

replaceメソッドは、変更が加えられた文字列を返しますが、現在の文字列は変更しません。

current_url = driver.current_url 
print(current_url) #prints the url of the current window. 

current_url = 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 
+0

ありがとう:

あなたはそのように使用する必要があります。今働いている – user3190414

関連する問題