seleniumだと

2024年6月9日

Seleniumを使用して現在のURLを取得する方法は、先ほど示したコードと同じです。以下にその例を示します。

python
from selenium import webdriver # Chrome WebDriverのインスタンスを作成 driver = webdriver.Chrome() # URLに移動 driver.get("https://example.com") # 現在のURLを取得 current_url = driver.current_url print("Current URL:", current_url) # WebDriverを終了 driver.quit()

このコードでは、ChromeのWebDriverを使用してhttps://example.comに移動し、current_urlを使用して現在のURLを取得しています。 最後に、quit()メソッドを使用してWebDriverを閉じます。

未分類

Posted by ぼっち