python/selenium Web 驱动程序代码:
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)点击“登录按钮”; 然后我需要以某种方式捕获动态变化的 URL 每秒(加载访问 token 等),并捕获 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 - 网络驱动程序,Python : How to catch dynamically updating url with the appropriate value and save it to the variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35481533/