How do I generate a png file w/ selenium/phantomjs from a string?

后端 未结 4 1348
感动是毒
感动是毒 2020-12-18 04:42

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 searc

4条回答
  •  忘掉有多难
    2020-12-18 05:23

    It seems the lines

    f = open(myFile,'w')
    f.write(htmlString) 
    

    Are problematic, as the generated file is empty.

    I fixed this issue with

    with open(myFile,'wt') as f:
        f.write(htmlString)
    

    or you might have to add a

    f.close() to your code
    

提交回复
热议问题