Jak wygenerować plik png w / selen / phantomjs z łańcucha?

Używam selenum / phantomjs do tworzenia plików png html w python. Czy istnieje sposób na wygenerowanie png z łańcucha html lub uchwytu pliku (zamiast strony internetowej)? Przeszukałem dokumenty selenu i wyszedłem na Google, ale nie mogłem znaleźć odpowiedzi. Mam:

htmlString = '<html><body><div style="background-color:red;height:500px;width:500px;">This is a png</div></body></html>'
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"

questionAnswers(4)

yourAnswerToTheQuestion