How can you run python with a bookmark? - python

I am writing a script to log into web pages (I know it's a bad idea, and I don't care), but I need to run it with a bookmark from Firefox. Does anyone know how to help me?

There is no pre-made solution and as it stands, you left part of your question ambiguous.
But here is one possible outline on how you could accomplish what you want from completely inside firefox.
First off you need to get python in the browser, but it is normally compiled into machine code. The solution is the Transcrypt project, which is Python is transcompiled into javascript and that script is then loaded into your browser. This allows you to run python code.
Extensions to python are made so it can access the DOM in a similiar way you can from javascript.
The transcrypt website has some examples, and some more can be found at a draft page at Mozilla.
Your bookmarklet would be to load a script to load transcrypt and feed it your python code, something like
javascript:(function(){var el=document.createElement('script');el.src='file:///something/something/transcript_loader_and_my_python_code.js';document.body.appendChild(el);})();
But the exact bookmarklet would depend on how you go about things. Writing transcript_loader_and_my_python_code.js is on your own, but if you get the examples from the links above working it should be trivial.

Related

Python Behave feature file warnings

I am not new to web automation with selenium but I am very new to python I am trying to create my own dynamic structure. With a little bit effort I can do the BE coding with python but when it comes to behave feature file I don't get the problem I am having. Basically my code works fine evet step that I have is implemented and it runs but when I am on PyCharm ide and open feature file my feature file looks like this
feature file
I couldn't find a solution online can anyone help me with this so steps can look normal and I can navigate to them by clicking ctrl + LMC
The problem is that PyCharm does not find the step definition.
Could you attach the directory tree of your project? It's possible that you don't follow Behave standards and that's why PyCharm is not able to find where the steps are defined.

Python and Django Source Code Navigation in Emacs

I am wondering if there is a way to to navigate Python(Django) code in Emacs similar to how one can M-. for Common Lisp code when using SLIME.
I have installed ELPY and a mode called python-django. However, they do not seem to provide this functionality.
I am particularly interested in doing this why developing using Django. However, even navigation for standalone Python projects would be nice.
I will give dumb-jump a chance.
It is not as fancy as other go-to-definition methods, as it only searchs for some predefined regex in your project. But it simply works most of the time, and you can add your own regex if you need them.

What do I need to do for adding python executable to HTML?

I made my own game in python using turtle graphics and I want to convert it to an executable file to run in HTML, is there any additional information I should know
Edit: An executable is not likely what you're looking for per Chris' answer. He also provides info about making an installer, if you do want to accomplish that. My answer addresses getting your Python game running in the browser.
When I initially saw this question, I thought it wasn't a thing. However, Python is just a language. Anything can interpret and run Python logic. It's just a matter if someone has built something that works in the browser and interprets Python.
After some Google searching, I found Skulpt: http://www.skulpt.org/. It appears to be a Javascript implementation of a Python interpreter. This is important because browsers only understand Javascript, not Python.
Something worth noting is that Skulpt appears to only have partial support for Python 3. It mostly focuses on Python 2. This could be a major concern because Python 2 is scheduled for end of life January 1st, 2020 (at least, that's what pip told me).
There are examples of using Skulpt on its page. Heads up that you'll likely need to learn some amount of Javascript, but if you're comfortable with Python already, that shouldn't be terrible.
Edit:
There also appears to be Brython: https://brython.info/. This is a Python 3-focused implementation. At first glance, it looks a little easier to use, too.
Hope this helps!
Please know that executables (.exe) & browsers tend not to work together.
See this stackoverflow question referring to .exe's & html The long & short of it is that you can setup .exe's so they can be downloaded, but not rendered in the browser.
If you want to convert your script to a .exe file, you'll need something like pyinstaller. Here's a link to some info about installing & using it.
TheBeege's answer is on point with rendering in the browser with python when you already have code written with turtle. I just wanted to make sure anyone coming here looking for info on python with executables could find it.

Using Selenium Webdriver with python/ruby/perl

I am trying to retrieve links programatically that use javascript for their retrieval. For this purpose I have decided to use Selenium which has been suggested by many for this purpose. The machine is command line based linux machine on which I am going to execute has Python2.4 ruby1.8.5 and perl 5.8.8 and I can strictly use the above mentioned versions only for this task in any programming language mentioned.
Being an absolute beginner I am getting confused with lot of terms with selenium and its compatibility with the above mentioned 'versions' of programming language. I tried reading http://docs.seleniumhq.org/docs/03_webdriver.jsp but was just lost in all those terms related to selenium. Also my purpose in not actually testing my web application. So for my simple purpose of just executing javascripts that retrieve links is there any step by step approach that a beginner like me should know and follow?
Have you looked at the WWW::Selenium module?

Execute a python script from firefox, on a very specific app, just to let firefox provide the graphical IDE

So, I've been searching the topic for quite a while, but I am unable to find out whether it is possible or not. I suspect not, but I need to be sure.
What I'm doing:
I am building a fancy web app that uses xml, xsl and javascript. However, I need to do some transformation to a text file to convert it into a proper xml file. To do this, I use a python script.
What I need:
I am working to make as easy as possible the use of the app, but this gets kind of destroyed when the user has to execute a terminal script before anything. I need a graphical IDE for python, but I just don't have time to learn how to make one, and I would love that the entire app would work within the same web environment, much more intuitive for the user. Then, a really easy way to do that would be to use Firefox as the IDE, for example choosing the file to be transformed through it, and launching from there the python script.
What I require:
I need compatibility only with Firefox. But of course any system capable to install Python and Firefox should work as well. The user would happily install both programs, as long as they have interest in the app.
What I don't know:
Is that possible, to execute an external python script? If not, for security reasons I imagine, is there any way for the user to allow it? Maybe through the installation of a plugin?
maybe http://mozex.mozdev.org/ is what I am looking for?
Thanks!
Gerard
Yes, It is possible to execute an external python script. You can use a simpleServer (example) that receives a (Ajax) request from your page and calls a subprocess or os.startfile to launch the script. In fact, you can call the function itself from within the server and return the result (e.g. as json) to the page and use your javascript to handle it.
If you're after actually using python in firefox, rather than having the server side written in python (although the webserver can of course be running locally), I would guess pythonext (used to be pyxpcomext) is what you need.

Categories

Resources