Prototyping 7 May 2013: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 21: Line 21:
   install OSX command line tools - > https://github.com/kennethreitz/osx-gcc-installer/
   install OSX command line tools - > https://github.com/kennethreitz/osx-gcc-installer/
   install homebrew - > http://mxcl.github.io/homebrew/
   install homebrew - > http://mxcl.github.io/homebrew/
<source lang="python">
#!/usr/bin/python
import cgi, urllib2, html5lib, urlparse
import cgitb; cgitb.enable()
print "Content-type: text/html"
print
q = cgi.FieldStorage()
url = q.getvalue("url","http://pzwart3.wdka.hro.nl/wiki")
f = urllib2.urlopen(url)
t = html5lib.parse(f,treebuilder="etree",namespaceHTMLElements=False)
print f.info().get("content-type")
for a in t.iter("a"):
    href = a.get("href")
    href = urlparse.urljoin(url, href)
    print '<a href="?url={0}">{0}</a><br>'.format(href)
#links = list(t.iter("a"))
#l = links[0]
#print f.read()
#print "hello"
</source>

Revision as of 13:40, 7 May 2013

Alternative Browsers


  • CGI / html5lib...


 * python on osx:
 
 install OSX command line tools - > https://github.com/kennethreitz/osx-gcc-installer/
 install homebrew - > http://mxcl.github.io/homebrew/
#!/usr/bin/python

import cgi, urllib2, html5lib, urlparse
import cgitb; cgitb.enable()

print "Content-type: text/html"
print

q = cgi.FieldStorage()
url = q.getvalue("url","http://pzwart3.wdka.hro.nl/wiki")
f = urllib2.urlopen(url)
t = html5lib.parse(f,treebuilder="etree",namespaceHTMLElements=False)

print f.info().get("content-type")

for a in t.iter("a"):
    href = a.get("href")
    href = urlparse.urljoin(url, href)
    print '<a href="?url={0}">{0}</a><br>'.format(href)

#links = list(t.iter("a"))
#l = links[0]

#print f.read()
#print "hello"