I want to implement a Python script to act as my OAuth2 endpoint, since I'm trying to write a Soundcloud app. Part of the authentication process involves visiting a Soundcloud page where you can sign in and grant access to the given Soundcloud application.
I'd like to be able to open that webpage in a browser using Python 3, which you can do with the webbrowser object. You can see on the documentation that launching a text-based browser blocks execution; I want to block execution whilst the webpage is open in a GUI-based browser.
Does anyone know whether this is possible?
This might be impossible to do portably. For example, if Firefox is already running on Linux, the second invocation of firefox http://url will find out that an instance using the same profile, will send a message to the other process to open that URL in a tab, then exits immediately.
However, you could accomplish the same thing by sending the authentication tokens to a server, and simultaneously polling the server for credentials in the python script.
Related
Never done this but, I'm trying to build a program, that would scrape a google classroom site specific to the user that's logged in. Even when logged in the main browser google denies the request and instead gives me authentication error (I need to login in other words) how can I be logged in, in the program so that google accepts my request and grants me to scrape classroom sites.
Tried this solution but without luck: Logging into Google using Python
It was published a while ago and google could have changed the requirements for these kind of program authentication.
What I desire is to get into the section only available for me when I'm logged in, e.g. content of my classroom and grab some text from it, is it even possible?
It would be expensive to try and implement a log-in mechanism, especially with all the 2FA requirements of Google solutions today.
What would be quicker and usually works in software automation today is to have a manually logged in session and then start the browser with the user data directory pointed to it. This is how it's usually achieved and the relogin is done manually from time to time, only when needed. More info on how to set up a user data directory here.
This gets you up and running pretty fast.
I am running automation with Selenium and Python on Opera web driver, when I enter the specific page that I need, a request is sent to the server, it is authenticated with anti-content which blocks me from requesting it, then the only solution is to get the returned JSON after sending the request, I had checked selenium-wire, but I think it doesn't fit my needs, I thought if there is another way to do that, any suggestions?
You can try to use Titanium Web Proxy. It is a proxy server and can be installed via Nuget package and used with Selenium.
string body = await e.GetResponseBodyAsString();
Reference:
https://github.com/justcoding121/Titanium-Web-Proxy/issues/176
https://www.automatetheplanet.com/webdriver-capture-modify-http-traffic/#tab-con-9
Hello there are some pages which is created to be impossible automatize the request.
That rule works in JavaScript and there are companies which makes this detection and close the access for a bot.
So I am sorry to cannot solve your problem, I tried to do the same as You and there are not way.
I'm trying to build a project using Youtube's API and Python3.
As mentioned in the Quick Start guide:
The sample attempts to open a new window or tab in your default browser. If this fails, copy the URL from the console and manually open it in your browser.
I'm using MacOS Terminal which runs the script but I really do need to copy the URL into my browser.
I guess the problem is in my machine, and I'd like to find a solution how to fix it, as it would be faster and easier, each and every time I run the script.
I've tried to find similar thread, with no luck.
If anyone can guide my through, or send me a link, for how to solve this problem.
Thanks,
Yoav.
You need a BROWSER environment variable set. This points to the location of the browser.
Use getenv BROWSER to see if it is already set
*Command may be different depending on version of Mac OS
Solution (source):
I've used the run_console() which don't attempt to run the browser, but ask for the client to open it manually.
To make it run the browser automatically, you should use run_local_server() method as shown in the example below.
The run_console function instructs the user to open the authorization
URL in their browser. After the user authorizes the application, the
authorization server displays a web page with an authorization code,
which the user then pastes into the application. The authorization
library automatically exchanges the code for an access token.
credentials = flow.run_console()
The run_local_server function attempts to open the authorization URL in the user's browser. It also
starts a local web server to listen for the authorization response.
After the user completes the auth flow, the authorization server
redirects the user's browser to the local web server. That server gets
the authorization code from the browser and shuts down, then exchanges
the code for an access token.
credentials = flow.run_local_server(host='localhost',
> port=8080,
> authorization_prompt_message='Please visit this URL: {url}',
> success_message='The auth flow is complete; you may close this window.',
> open_browser=True)
Thank you #Hassan Voyeau for the help.
I want to run a python program (kinda like this) from a browser
Anyway, as you see it has a few inputs, and i would like to "translate" that into a kind of form
def addNew():
appendBase = open('dBase.cfg','a')
uname = input('Username: ')
pword = input('Password: ')
appendBase.write(uname+','+pword+'\n')
print('\nAdded new profile: \n'+uname+','+pword)
appendBase.close()
Also i dont know how to get the print to the page, so it can show it
I've just started learning, so go easy on me, please
It is not possible to actually run this in the browser, for various reasons.
you can't run python in browsers. only javascript
you can't open local files from a browser
there's no command line to input from some terminal
Most things you see on the web have two parts
a part that actually runs in the browser. Written in HTML and javascript
another part where the browser connects, to send and receive data. That can be done in any language, including python. However, that part is not visible in the browser
The two parts communicate using HTTP protocol. So, start by reading a bit on HTML/javascript (W3Schools is an easy way to get started). When you feel comfortable with that, practice with a python web framework (django is the most popular, but flask is the easiest to get started), and see how javascript uses HTTP to connect to that.
I need to create an application, which logs into a website (username/pwd) with my credentials but this website has no API or authentication protocol (its not been updated since 1998, but I need data from it continuously).
Is there anyway to do this? Preferably in python but can use any language or tools.
I have been searching google but most people have APIs to work with.
As stated in the comments, you can use the Python Selenium bindings to get this set up fairly painlessly.
Another option is the Mechanize family of tools (Python's is http://wwwsearch.sourceforge.net/mechanize/)
If you want a less heavyweight solution (that doesn't require a hefty web browser instance like Selenium or any third-party packages) you can most likely use the curl command-line client to authenticate to the app and send your requests, then put the curl commands into a shell or Python script.
You can get a head start on developing a curl solution using the Chrome dev tools:
With the dev tools open, bring up the Network tab
Select the "Preserve log" checkbox
Manually navigate to your web app in the browser and log in
Perform any other actions you want to automate
You should now have a list of requests in the Network tab
Scan through the requests and determine which are important (e.g., GETs for images can be ignored)
For each request you want to include in your script, right click the item and click ""Copy as cURL" option to get the curl equivalent of the request in your clipboard.
The string Chrome places in your clipboard will be very verbose; you can likely remove several bits and still have a working request, if you want to clean it up.
Parameterize the requests as necessary, and you should have the beginnings of a working shell script for your task.