我有一个python脚本,运行该脚本以循环方式截取屏幕截图并保存所有这些图像。但目前,所有的图像都存储在Python35文件夹中。在
因此,我希望用户输入一个文件夹的名称,并用这个名称创建一个。在
我知道使用makedirs函数并通过newpath=r'C:/users/../'指定路径。在
但是如何将用户指定的新文件夹名附加到路径中呢?在
(编辑)这是代码I有:在import openpyxl
import re
import os
import time
from PIL import ImageGrab
import webbrowser
source_excel=input('Enter the source excel file name-> ')
wb=openpyxl.load_workbook(source_excel)
sheet=wb.active
strt=int(input('Enter starting range-> '))
end=int(input('Enter ending range-> '))
#NEED THE CHANGE HERE
foldname=input("Enter a folder name to create where images will be saved")
newpath=r'C:\Users\rnair\AppData\Local\Programs\Python\Python35\'demofile
# Loop to get the link from excel and take the screenshot by opening the browser for each link
for q in range(strt,end):
getme=q,sheet.cell(row=q,column=1).value #get link from excel file
ab=getme[1]
#myopener=Myopen()
rowc=str(strt)
url=ab
webbrowser.open(url) #opens browser for the link fetched
time.sleep(7) # Delay to wait for the page to load completely
im=ImageGrab.grab()
os.chdir(newpath)
im.save("Row"+rowc+".jpg","JPEG") # Saving image to file
strt=strt+1