I have written a scraper tool in Python which when executed produces a CSV file of information. I wish to embed it in a HTML, so within the page the user is able to run it and then the results are displayed on the page from the CSV file. How can I do this?
If you only need to display the information on a website, no interaction back with your python script, all you need to do is just write the results into a HTML file and .format() it appropriately.
However, since this requires the user to be able to run and view the results with interaction with your python script, you would need a web server.
You could try the two most popular python based web servers that can accomplish this: Flask and Django or you could use the less common but more lightweight Simple HTTP Server.
But, do keep in mind that an easier alternative (if possible) will be to just use a GUI such as Tkinter or PyQt or EasyGUI.
Related
I want to make a script in python that interacts with a webpage that has quite a lot of javascript in it (it's a webpage that computes a bunch of physics stuff).
I don't want my code to break if the page formatting changes and I want it to run offline so I would prefer my script to run on a local html copy of the page I got (all the JS code is accessible in the HTML source, there is no call to an external server). I wanted to use the requests library to do it, but it only works with URLs. Is there any library to do this? Note that I want to interact with the HTML (input values and look at the outputs etc..), I know that I can parse the file but that's not what I'm asking. I'm also totally new to web bots or anything related.
Right now I can open my .html version of the page offline with chrome and interact with it, so there has to be a way to automate this somehow. I'm also not against using something else than python if there is a better library for this in another language.
interesting question, best way I can think to do that is use a web framework and then just scrape the data using requests. I am familiar with flask and its simple to use but im sure there are other options as well
I have a python script that collects data on some virtual machines. I want to display this data in a webpage.The web page must be dynamic since the script will run continuously and the data must be updated every time the script runs. I possibly want this data displayed in a table but I am not sure what direction to go?
You could use Apache or another web server. Set up an HTML web page with javascript. I recommend using jQuery as it makes making ajax calls so much easier. Have your javascript/ajax/jquery call your python script every x minutes/seconds.
Ensure your apache server is setup to run CGI scripts and ensure they are set with read and execute permissions.
I am planning to build a simple web page that has an upload file option, submit button and a table to display the results.
The file i would be uploading is an XML file.
Upon submit, a python script should validate the XML file and display the discrepancies in the HTML page.
What is the best way to proceed with the front end and python integration? I have already validated the XML using python scripts but i am unable to find out a way to integrate it with HTML, upload & submit buttons.
Kindly help or let me know if you need any further details.
You'll want to use a web framework to do this. Some good options for python are Flask and Django. HTML is meant to run on the client's browser, where Python (in this situation) is meant to run off of a server. Django, Flask, and others make this quick and easy to do.
I have created a really cool Python program that I want all of my friends to try out. I really want to put the running code onto a website so people can try it all around the world. Is it possible to run Python code on a HTML page? If so, how?
In answer to your question: Yes, this is possible.
If you merely want to share your code with your friends, and allow them to try it out (even without them having Python installed), in browser, then there are a number of tools that you can use.
For example, with https://trinket.io/ , you can embed a snippet of python code in an HTML webpage or share it via a link.
Update:
Another alternative online python site is http://repl.it/. Repl.it has compiled the CPython interpreter into Javascript, using an LLVM -> Javascript compiler. It is opensource, so you could even self-host if you wanted. Caveat: Some of the libraries still have bugs in them.
The simple pedestrian solution is to create a WSGI wrapper. You can configure your web server to accept input through a form (typically) and feed that to your Python program as input, then display the program's output as the response to the form submission. Thus your program runs on the server -- which needs to have the required services and resources -- but the user interaction happens simply using the client's web browser.
There are more-complex interaction models but this is how the entire web 1.0 was set up and is quick and easy to get going. (The spec back then was the similar platform-independent CGI API.)
I have a program written for text simplification in python language, I need this program to be run on a browser as a plugin... If you click the plugin it should take the webpage's text as input and pass this input to my text simplification program and the output of the program should be again displayed in another web page...
Text simplification program takes input text and produces a simplified version of the text, so now I'm planning to create a plugin which uses this program and produces simplified version of text on the webpage...
It will be of great help if anyone help me out through this...
You would need to use NPAPI plugins in Chrome Extension:
http://code.google.com/chrome/extensions/npapi.html
Then you use Content Scripts to get the webpage text, you pass it to the Background Page via Messaging. Then your NPAPI plugin will call python (do it however you like since its all in C++), and from the Background Page, you send the text within the plugin.
Concerning your NPAPI plugin, you can take a look how it is done in pyplugin or gather ideas from here to create it.
Now the serious question, why can't you do this all in JavaScript?
If you want an easier way than trying to figure out plugins, make it run as a webservice somewhere (Google App Engine is good for Python, and free), then use a bookmarklet to send pages from the browser. As an added bonus, it works with any browser, not just Chrome.
More explanation:
Rather than running on your own computer, you make your program run on a computer at Google (or somewhere else), and access it over the web. See Google's introduction to App Engine. Then, if you want it in your browser, you make a "bookmarklet" - a little bit of javascript that grabs the web page you're currently on (either the code or the URL, depends on what you're trying to do), and sends it to your program over the web. You can add this to your browser's bookmark bar as a button you can click. There's some more info on this site.