用Python Selenium中列表中的text/str替换url的一部分

用Python Selenium中列表中的text/str替换url的一部分,python,list,selenium,url,get,Python,List,Selenium,Url,Get,我有这个代码和这个页面,例如,123号可以随时更改 def get_url(new_list): driver.get("https://siteexample.com/index/page/{}".format(new_list)) new_list = [0] get_url(new_list) 因此,我有另一个代码来替换新列表中的数字0 active_page_num = driver.find_element(By.CSS_SELECTOR, "

我有这个代码和这个页面,例如,123号可以随时更改

def get_url(new_list):
    driver.get("https://siteexample.com/index/page/{}".format(new_list))

new_list = [0]

get_url(new_list)
因此,我有另一个代码来替换新列表中的数字0

active_page_num = driver.find_element(By.CSS_SELECTOR, ".active .page").text
active = int(active_page_num) # if the page 22 is currently active
new_list[0] = active

但是现在url是,例如,并且因为[]而给我一个错误,因为它无法识别它是一个列表。如何获取列表中要放置在url末尾的正确数字。

如果函数
格式(新列表[0])中始终只有一个元素,则访问第一个元素。
。最好是通过int,为什么要使用list?有必要吗?是的,为什么不使用变量呢?我的意思是只要
new_list=0
当然这不是list。非常感谢您的帮助,它很有效,并且将尝试使用variable。