leave our simplified solution as homework assignment to improve upon we then test to see if the target site has simple logout url that we can redirect to and if sowe force the browser to do so if the target site (such as facebookrequires the user to submit form to force the logoutwe begin iterating over the dom and when we discover the html element id that is registered to the logout form we force the form to be submitted after the user has been redirected to the login formwe modify the endpoint of the form to post the username and password to server that we control and then wait for the user to perform login notice that we tack the hostname of our target site onto the end of the url of our http server that collects the credentials this is so our http server knows what site to redirect the browser to after collecting the credentials you'll notice the function wait_for_browser referenced in few spots abovewhich is simple function that waits for browser to complete an operation such as navigating to new page or waiting for page to load fully let' add this functionality now by inserting the following code above the main loop of our scriptdef wait_for_browser(browser)wait for the browser to finish loading page while browser readystate ! and browser readystate !"complete"time sleep( return pretty simple we are just looking for the dom to be fully loaded before allowing the rest of our script to keep executing this allows us to carefully time any dom modifications or parsing operations