There is a Python script using selenium. The bottom line is that it opens pages and tears out photos from them, but some photos require authorization, so the first thing to do is to authorize by filling in the login and password forms, click on the authorization button and get to the authorized view of VK. But with the next request of the type driver.get(url) turns out that the page opens without authorization. I assume that cookies should be used, but I don’t quite understand how to do this. That is, there is the line allcoockie = driver.get_cookies() , but I don’t really understand how to apply it to the new- allcoockie = driver.get_cookies() question - how can I leave the authorized page?

  • I found it myself - I just had to wait for the page to load in time.sleep () - Riv Shiell
  • 2
    If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Mikhail Vaysman

2 answers 2

You need to wait before the page is loaded. If it does not help, try to refresh the page after applying the cookies.

Use .Sleep () will not light. It is better to wait until the page is fully loaded by the browser. So errors will be eliminated from scratch with a poor Internet connection.

  • The concept of "fully loaded page" is quite complicated (you can simply wait until the desired item is loaded using WebDriverWait, but this has nothing to do with authorization: for example, cookies are sent to the server in the request in the header - loading the subsequent server response in any way to the success of the package cookies are not affected. - jfs
  • And the fact that there are no such methods in the selenium itself does not at all mean that this is not possible in principle. Not so difficult as it seems. I somehow wrote a method that waits until the end of the page load, and even wrote a method that waits for the end of the processing of agax requests, which works on almost all sites :) And I wrote these methods once more when I sat down to teach selenium and Sharp in principle ... Without much experience :) - Andrew
  • the phrase "quite difficult" is not synonymous with "impossible in principle." “For every complex problem, it’s clear, simple, and wrong.” - jfs

As a result, the easiest way for the first download turned out to be the sleep () method, which waited for the page to load. As noted above, this is not the safest method in case of a bad connection, but in the context of a quick solution to the problem, it is suitable.