Display string data from Python script using HTML - python

Is there any way that shows data from python script using HTML?
For example, I want to generate random numbers for each seconds at WebSocketClient.py and trasmit them to Web server. On WebServer.html, random numbers are displayed for every seconds.
PC (Server)
- WebServer.html (port is specified)
Python(Raspi, Client)
- WebSocketClient.py (Input:IP of PC and port)
I searched several methods, but they are not suitable for me. I guess 'WebSocket' is the best way to do this, however most of examples are .html(client) and .py(server).

If I understand your question correctly, you need to evaluate an HTML input (from a web server) using a python script on your client.
This would involve two steps: Retrieving the input data from the web server and parsing it.
Take a look at the topics of web scraping and html parsing.
Beautiful Soup is a widely used library for this purpose.

Related

Display Data In Real Time With Django

I have a simulator application that continuously spits out data, formatted in JSON, to a given host name and port number (UDP). I would like to be able to point the simulator output to a Django web application so that I can monitor/process the data as it comes in.
How do I receive and process data in real time using Django? What tools or packages are available to accomplish this? I did come across this answer: How to serve data from UDP stream over HTTP in Python?, but I don't completely understand.
Ex: Similar to this page: http://money.cnn.com/data/markets/
ALSO, I don't need to store any of the streaming data in a database. I just need to perform lookups based on the streaming data. Maybe it's not a Django issue at all?
Using Javascript.
Create a webpage with all the results, and then use javascript to collect the data from the page, and update it every X seconds.
Have the webpage be the JSON data, and the javascript grab it an interpret it.
get html code using javascript with a url
Then update the page using javascript. ww3 schools has great JS tutorials

Python Web Scraping W/O Beautiful Soup or non-default modules?

I'm completely and utterly new to web scraping, and have only previously used Python to make myself an IRC using sockets, ect.
What I want to do with my IRC is have the client grab an IP or list of IP's from a free blog I made using Google Blogger.
So naturally, I need to do some web scraping in order to get this information.
The problem is, how can I do this without requiring a client downloading this to have to install addons like Beautiful Soup in order to get it working?
Summary of Problem:
Need to grab some data from a webpage without the use of third party modules.
I've done a bunch of Google'ing, but only find solutions using Beautiful Soup. (And even with that, It's hard to understand)
import urllib2,re
content = urllib2.urlopen("http://somme.url").read()
print re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",content)
something like that

is there a way to capture network calls a site makes using python?

I've looked and urllib(2), mechanize, and Beautiful Soup in hopes to find something that captures network calls such as pixel/beacon fires from a page. Unfortunately i'm not very familiar with any of them, and also not very clear on how to go about my search.
I'd like to use python to run through a series of web urls, and capture each ones networks call aka pixel fires. Would anyone know of a means or library i can start from inorder to accomplish this??
looked into webscrappying, but i don't want the html, instead i beleive i'm looking for the GET request the site makes.
If I understand what you want, you want to log what requests a browser makes when displaying a page, in respect of many pages.
Your options are to script a browser using python (See: http://wiki.python.org/moin/WebBrowserProgramming), or script the browser using javascript, and output your results in some way (I suggest JSON, over a request or to a file), and analyse them in python.
You'll probably find it easier to do the scripting in javascript, honestly.
Another possibility if you have access to the Firefox web browser is to install Firebug, a powerful debugging tool that gives you the option to display all network traffic from a web page in the browser console. In order to transfer the output from the console to a file you will need to install the ConsoleExport plugin for Firebug.
You will now be able to capture all the traffic from a web page to a file which you can then parse with Python.

Using Python 3.3 to access blocked webpages

I'm trying to download webpages off the internet. I'm able to steal the HTML (with URLlib), but I can't download images correctly. There's already a question for that though. My question is, is there any way I can use python to bypass a firewall to access 'blocked' webpages?
Ideally it would be using some obscure code or module, but if it's impossible, could someone tell me a good workaround using a different method (like a proxy)?
If you want to extract images from a HTML page, you need to parse it with re module
import re
using regex to extract only the img src tag. You can also use a parser alredy written. For example BeautifulSoup > http://www.crummy.com/software/BeautifulSoup/
A firewall is a passive component of a perimeter defense into a computer network that can also serve as contact points between two or more sections of the network, ensuring a protection in terms of security of the network itself. So you have to work directly in the network, not through the code language.

transferring real time data from a website in python

I am programming in Python.
I would like to extract real time data from a webpage without refreshing it:
http://www.fxstreet.com/rates-charts/currency-rates/
I think the real time data webpage is written in AJAX but I am not quite sure..
I thought about opening an internet browser with the program but I do not really know/like this way... Is there an other way to do it?
I would like to fill a dictionnary in my program (or even a SQL database) with the latest numbers each second.
please help me in python, thanks!
To get the data, you'll need to look through the javascript and HTML source to find what URL it's hitting to get the data it's displaying. Then, you can call that URL with urllib or your favorite python library and parse it
Also, it may be easier if you use a plugin like Firebug that lets you watch the AJAX requests.

Categories