0

I'm trying to save a webpage through selenium and "ctrl+s" via pyautogui. But I couldn't change the directory for saving when the save file window comes. The examples I could find about it are to save the screenshot in a specified directory. However, I'd like to save exactly in the current working directory, in case it may need to work in other computers.

page = webdriver.Chrome(executable_path='chromedriver.exe')
page = page.get(url)
pyautogui.hotkey('ctrl', 's')
time.sleep(3)
path = os.getcwd()
pyautogui.typewrite('foo' + '.html')
pyautogui.press('enter')

Is it possible to insert os.getcwd() somewhere in this code? I tried to add os.getcwd() at some places(such as (path + 'foo' + '.html')) but it didn't work, as expected. Or is there any other way to do?

mulaixi
  • 183
  • 2
  • 11
  • is there a point in using pyautogui for this? selenium lets you access `page_source` which you can then save in whatever path you want. – Chase Oct 28 '20 at 06:30
  • I don't know how to do it with selenium either. I tried several ways to save webpage but the statics created problem. As a result I ended up [here]: (https://stackoverflow.com/a/53966809/5619835) As the comment suggest there, I could change the directory after saving the file, but I'd like to know if there is a way to do it in a short way, before saving the file. @Chase – mulaixi Oct 28 '20 at 06:40

0 Answers0