我需要在屏幕截图文件名中添加当前网址。
这是代码:
driver = webdriver.Firefox()
driver.get("http://www.google.com")
driver.save_screenshot("image.png") # save a screenshot to disk
print driver.current_url
driver.quit()
如何用driver.current_url替换image.png?
答案 0 :(得分:0)
对于您问题中给出的具体示例:
driver.save_screenshot(driver.current_url.replace('://','_'))
更一般地说,由于您的问题源于特殊字符,您可以执行以下操作:
chars = [':','/','%'] # add more if needed
image_name = driver.current_url
for char in chars:
image_name = image_name.replace(char,'_')
driver.save_screenshot(image_name)