Skip to content
Advertisement

is there a way to parse python-flask oauth2

I have code something like below –

JavaScript

Here when app.run(host=’127.0.0.1′, port=’80’) runs gives me URL – http://127.0.0.1/getcode. I need to mannually open enter username and password and again then one more window comes to enter YOB, which then give me something like –

JavaScript

Here My question is there a way to avoid doing this manually opening the browser and enter credentials and get the code. can we parse the entire thing in python?

Advertisement

Answer

Sounds like a job for Selenium! It can open a web browser and parse the required details for you.

Run the following code after starting the server

JavaScript

Now, this handles the first part of your question i.e. automate the login process. Now I’m not sure what’s your next goal but I assume you want the code variable in the URL, which I assume is returned by the OAuth2 funtion.

We can achieve this by simply getting the URL and parsing for the code variable

To get the URL

JavaScript

Now, you can simply parse the URL using urlparse.

JavaScript

Some sources you can refer:

  1. https://medium.com/swlh/automate-data-collection-with-selenium-in-python-246a051206e2
  2. Fill username and password using selenium in python
  3. Find URL after clicking a link
  4. https://stackoverflow.com/a/5075477/11029298
  5. https://selenium-python.readthedocs.io/getting-started.html
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement