Created
November 14, 2014 13:48
-
-
Save mundry/1f5fe815d89d98171d73 to your computer and use it in GitHub Desktop.
Boiler plate code to combine elements from different pages on a single page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
# -*- coding: utf-8 -*- | |
from io import StringIO | |
from lxml.html import builder as E, HTMLParser, parse, tostring | |
from urllib2 import urlopen | |
parser = HTMLParser() | |
log = urlopen("https://chromium.googlesource.com/chromium/src/+log/HEAD").read().decode("utf-8") | |
tree = parse(StringIO(log), parser) | |
css = [] | |
for link in tree.getroot().iterlinks(): | |
if link[0].tag == "link": | |
if not link[0].attrib['href'].startswith("http"): | |
if link[0].attrib['href'].startswith("//"): | |
link[0].attrib['href'] = "https:{}".format(link[0].attrib['href']) | |
else: | |
link[0].attrib['href'] = "https://chromium.googlesource.com{}".format(link[0].attrib['href']) | |
css.append(link[0]) | |
breadcrumbs_element = tree.getroot().cssselect('div.breadcrumbs')[0] | |
log_element = tree.getroot().cssselect('ol.log')[0] | |
revs = urlopen("http://chromium-status.appspot.com/revisions").read().decode("utf-8") | |
tree = parse(StringIO(revs), parser) | |
for link in tree.getroot().iterlinks(): | |
if link[0].tag == "link": | |
link[0].attrib['href'] = "http://chromium-status.appspot.com{}".format(link[0].attrib['href']) | |
css.append(link[0]) | |
revision_element = tree.xpath('/html/body/center[2]')[0] | |
css.append(E.STYLE("html{background:#FFF}body{max-width:100%}#crcomp-log{float:left;max-width:56%}")) | |
print tostring(E.HTML( | |
E.HEAD( | |
E.TITLE("Cr Source Comp"), | |
*css), | |
E.BODY( | |
E.DIV(breadcrumbs_element, log_element, id="crcomp-log"), | |
E.DIV(revision_element, id="crcomp-revs")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment