Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions python/INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
DEPENDENCIES
------------
* Python >= 2.6
* PyQt4 >= 4.8.0
* Qt >= 4.7.0

-> Windows
-------
You can download the required programs here.

Python - http://www.python.org/download/
Qt4 - PyQt4 comes packaged with the Qt runtime library(s)
PyQt4 - http://www.riverbankcomputing.co.uk/software/pyqt/download

-> Ubuntu
------
Follow these instructions.

Packages to install:

* python
* python-qt4

Instructions
------------
Open a terminal window, and enter the following command:
"sudo apt-get -y install python python-qt4"

All the required packages should be automatically pulled in and installed.
31 changes: 31 additions & 0 deletions python/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
DESCRIPTION
----------------
PyPhantomJS is a minimalistic, headless, WebKit-based, JavaScript-driven tool, based on the PhantomJS project.

It has native support for different web technologies: DOM handling, CSS selector, JSON, Canvas, SVG, and of course JavaScript.

See the quick start guide and more advanced examples which show various PhantomJS scripts, covering:
* http://code.google.com/p/phantomjs/wiki/QuickStart
* http://code.google.com/p/phantomjs/wiki/ServiceIntegration

* running regression tests from command line
* getting driving direction
* showing weather forecast conditions
* finding pizza in New York
* looking up approximate location based on IP address
* pulling the list of seasonal food
* producing PDF version of a Wikipedia article
* rasterizing SVG to image

PyPhantomJS is written in PyQt4 and Python. It runs on Linux, Windows, and Mac OS X.
Refer to the INSTALL file or Wiki links below for more information.
* http://code.google.com/p/phantomjs/w/list
* http://dev.umaclan.com/projects/pyphantomjs/wiki

Do not forget to consult the concise API Reference.
* http://dev.umaclan.com/projects/pyphantomjs/wiki/Api_reference
* http://code.google.com/p/phantomjs/wiki/Interface

If you want to contribute, please read the Contribution Guide.
* http://code.google.com/p/phantomjs/wiki/ContributionGuide
* http://dev.umaclan.com/projects/pyphantomjs/wiki/Giving_back
54 changes: 54 additions & 0 deletions python/networkaccessmanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
This file is part of the PyPhantomJS project.

Copyright (C) 2011 James Roe <roejames12@hotmail.com>
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

from PyQt4.QtCore import SIGNAL, QString, qDebug, qWarning
from PyQt4.QtNetwork import QNetworkRequest, QNetworkAccessManager

class NetworkAccessManager(QNetworkAccessManager):
def __init__(self, parent = None):
QNetworkAccessManager.__init__(self, parent)
self.connect(self, SIGNAL('finished(QNetworkReply *)'), self.handleFinished)

def createRequest(self, op, req, outgoingData):
if op == QNetworkAccessManager.GetOperation:
qDebug('HTTP/1.1 GET Request')
elif op == QNetworkAccessManager.PostOperation:
qDebug('HTTP/1.1 POST Request')
elif op == QNetworkAccessManager.HeadOperation:
qDebug('HTTP/1.1 HEAD Request')
elif op == QNetworkAccessManager.PutOperation:
qDebug('HTTP/1.1 PUT Request')
elif op == QNetworkAccessManager.DeleteOperation:
qDebug('HTTP/1.1 DELETE Request')
elif op == QNetworkAccessManager.CustomOperation:
qDebug('HTTP/1.1 CUSTOM Request')
else:
qWarning('Unexpected HTTP Operation Type')

qDebug(QString('URL %s' % req.url().toString()))

return QNetworkAccessManager.createRequest(self, op, req, outgoingData)

def handleFinished(self, reply):
qDebug('HTTP/1.1 Response')

headerPairs = reply.rawHeaderPairs()
for pair in headerPairs:
qDebug('"%s" = "%s"' % (pair[0], pair[1]))
Loading