WebDriver,Python:如何使用适当的值捕获动态更新 url 并将其保存到变量
WebDriver, Python: How to catch dynamically updating url with the appropriate value and save it to the variable
python/selenium 网络驱动程序代码:
elem = driver.find_element_by_css_selector("#username")
elem.send_keys("username")
elem = driver.find_element_by_css_selector("#password")
elem.send_keys("password")
driver.implicitly_wait(2) #seconds
elem = driver.find_element_by_css_selector("button")
elem.click()
def condition(driver):
look_for = ("url_which_contains_this_text")
url = driver.current_url
for look_for in url:
if url.find(look_for) != -1:
print url
return url
#page_url = driver.current_url
print url
在这段代码中:
1)用户登录;
2) 点击【=20=】;
然后我需要以某种方式捕捉动态变化的 URL
每秒(加载访问令牌等),并捕获 URL 哪个
包含值 "example_id=" 并将此 url 保存到变量并打印。
有人帮帮我吗?
我不确定这是否有效,因为我无法对其进行测试,但您可以尝试这样的操作:
required_url = ""
while True:
current_url = driver.current_url
if "example_id=" in current_url:
required_url = current_url
print('\n'+required_url)
break
else: print(current_url)
python/selenium 网络驱动程序代码:
elem = driver.find_element_by_css_selector("#username")
elem.send_keys("username")
elem = driver.find_element_by_css_selector("#password")
elem.send_keys("password")
driver.implicitly_wait(2) #seconds
elem = driver.find_element_by_css_selector("button")
elem.click()
def condition(driver):
look_for = ("url_which_contains_this_text")
url = driver.current_url
for look_for in url:
if url.find(look_for) != -1:
print url
return url
#page_url = driver.current_url
print url
在这段代码中: 1)用户登录; 2) 点击【=20=】; 然后我需要以某种方式捕捉动态变化的 URL 每秒(加载访问令牌等),并捕获 URL 哪个 包含值 "example_id=" 并将此 url 保存到变量并打印。
有人帮帮我吗?
我不确定这是否有效,因为我无法对其进行测试,但您可以尝试这样的操作:
required_url = ""
while True:
current_url = driver.current_url
if "example_id=" in current_url:
required_url = current_url
print('\n'+required_url)
break
else: print(current_url)