Using Selenium in Python to save a webpage on Firefox

前端 未结 4 2124
野的像风
野的像风 2021-01-01 17:47

I am trying to use Selenium in Python to save webpages on MacOS Firefox.

So far, I have managed to click COMMAND + S

4条回答
  •  甜味超标
    2021-01-01 18:25

    What you are trying to achieve is impossible to do with Selenium. The dialog that opens is not something Selenium can interact with.

    The closes thing you could do is collect the page_source which gives you the entire HTML of a single page and save this to a file.

    import codecs
    
    completeName = os.path.join(save_path, file_name)
    file_object = codecs.open(completeName, "w", "utf-8")
    html = browser.page_source
    file_object.write(html)
    

    If you really need to save the entire website you should look into using a tool like AutoIT. This will make it possible to interact with the save dialog.

提交回复
热议问题