Here are the examples of the python api lab10.request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
Source : lab11.py
with MIT License
from browserengineering
with MIT License
from browserengineering
def load(self, url, body=None):
headers, body = request(url, self.url, payload=body)
self.scroll = 0
self.url = url
self.history.append(url)
self.allowed_origins = None
if "content-security-policy" in headers:
csp = headers["content-security-policy"].split()
if len(csp) > 0 and csp[0] == "default-src":
self.allowed_origins = csp[1:]
self.nodes = HTMLParser(body).parse()
self.js = JSContext(self)
scripts = [node.attributes["src"] for node
in tree_to_list(self.nodes, [])
if isinstance(node, Element)
and node.tag == "script"
and "src" in node.attributes]
for script in scripts:
script_url = resolve_url(script, url)
if not self.allowed_request(script_url):
print("Blocked script", script, "due to CSP")
continue
header, body = request(script_url, url)
try:
print("Script returned: ", self.js.run(body))
except dukpy.JSRuntimeError as e:
print("Script", script, "crashed", e)
self.rules = self.default_style_sheet.copy()
links = [node.attributes["href"]
for node in tree_to_list(self.nodes, [])
if isinstance(node, Element)
and node.tag == "link"
and "href" in node.attributes
and node.attributes.get("rel") == "stylesheet"]
for link in links:
style_url = resolve_url(link, url)
if not self.allowed_request(style_url):
print("Blocked style", link, "due to CSP")
continue
try:
header, body = request(style_url, url)
except:
continue
self.rules.extend(CSSParser(body).parse())
self.render()
def render(self):
0
Source : reflow-chapter.py
with MIT License
from browserengineering
with MIT License
from browserengineering
def load(self, url, body=None):
self.timer.start("Downloading")
self.address_bar = url
self.url = url
self.history.append(url)
header, body = request(url, self.url, payload=body)
self.timer.start("Parsing HTML")
self.nodes = parse(lex(body))
self.timer.start("Parsing CSS")
with open("browser8.css") as f:
self.rules = CSSParser(f.read()).parse()
for link in find_links(self.nodes, []):
header, body = request(resolve_url(link, url), self.url)
self.rules.extend(CSSParser(body).parse())
self.rules.sort(key=lambda x: x[0].priority())
self.rules.reverse()
self.timer.start("Running JS")
self.setup_js()
for script in find_scripts(self.nodes, []):
header, body = request(
resolve_url(script, self.history[-1]), self.url)
try:
print("Script returned: ", self.js.evaljs(body))
except dukpy.JSRuntimeError as e:
print("Script", script, "crashed", e)
self.layout(self.nodes)
def setup_js(self):