title: How do I generate a png file w/ selenium/phantomjs from a string?
body: <p>I am using selenium/phantomjs to create png files of html in python. Is there a way to generate the png from an html string or filehandle (instead of a website)? I've searched through the selenium docs and googled but couldn't find an answer. I have:</p>
  
  <pre><code>htmlString = '&lt;html&gt;&lt;body&gt;&lt;div style="background-color:red;height:500px;width:500px;"&gt;This is a png&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;'
  myFile = 'tmp.html'
  f = open(myFile,'w')
  f.write(htmlString) 
  
  from selenium import webdriver  
  
  driver = webdriver.PhantomJS()
  driver.set_window_size(1024, 768) 
  #driver.get('https://google.com/') # this works fine
  driver.get(myFile) # passing the file name or htmlString doesn't work...creates a blank png with nothing
  driver.save_screenshot('screen.png') 
  driver.quit()
  
  print "png file created"
  </code></pre>