gpt4 book ai didi

python - 网络驱动程序,Python : How to catch dynamically updating url with the appropriate value and save it to the variable

转载 作者:太空宇宙 更新时间:2023-11-04 03:18:26 25 4
gpt4 key购买 nike

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) 点击“登录按钮”;然后我需要以某种方式捕获动态变化的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com