requests-html: Render w/o request doesn't execute inline JS

This lib looks great, thanks 😃… Just a note, I was expecting:

doc = """<a href='https://httpbin.org'>"""
html = HTML(html=doc)
html.render()
html.html

to output : <a href='https://httpbin.org'>

Instead I get the content from example.org, which is the default url.

How can I set the html content and then render it? I can’t seem to pass it to:

doc = """<a href='https://httpbin.org'>"""
html = HTML(html=doc)
html.render(script=doc)
html.html

either, as I get an:

BrowserError: Evaluation failed: SyntaxError: Unexpected token <
pageFunction:
<a href='https://httpbin.org'>

I could set the url to the local file and patch it in, but that solution seems lacking.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16

Commits related to this issue

Most upvoted comments

the following now works:

from requests_html import HTMLSession, HTML

session = HTMLSession()

doc = """
<!DOCTYPE html>
<html>
<body>
<div id="replace">This get's replaced</div>
<div id="add">This get's added to:</div>

<script type="text/javascript">
  function addText() {
  	document.getElementById("add").append(" Text");
  }

  document.getElementById("replace").innerHTML = "<input type='button' value='Click Here' onclick='addText()' />";
  </script>
</body>
</html>
"""
html = HTML(html=doc)
html.render()
print(html.html)