I am trying to use Selenium
in Python
to save webpages on MacOS Firefox
.
So far, I have managed to click COMMAND + S
to pop up the SAVE AS window
. However,
I don't know how to:
Could someone help?
Below is the code I have use to click COMMAND + S
:
ActionChains(browser).key_down(Keys.COMMAND).send_keys("s").key_up(Keys.COMMAND).perform()
Besides, the reason for me to use this method is that I encounter Unicode Encode Error when I :-
Write to a html file:
file_object = open(completeName, "w")
html = browser.page_source
file_object.write(html)
file_object.close()
Write to a csv file:
csv_file_write.writerow(to_write)
Error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in position 1: ordinal not in range(128)
with open('page.html', 'w') as f:
f.write(driver.page_source)