Sto usando selenio/phantomjs per creare file png di html in python. C'è un modo per generare il png da una stringa html o da un filehandle (invece di un sito Web)? Ho cercato tra i documenti del selenio e ho cercato su Google ma non ho trovato risposta. Ho:Come posso generare un file png con selenio/phantomjs da una stringa?
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"
Hai provato 'file: /// PercorsoFile/tmp.html'? –
Questo mi dà anche un file png vuoto. È documentato da qualche parte? –
No. Non ho mai usato PhantomJS, ma il file: /// è ciò che i browser usano per andare a un file. Non ho sfuggito alla riga sopra (e ora non posso modificarlo) ... ti sei assicurato che fuggisse? –