generate image (e.g. jpg) of a web page?

后端 未结 5 1317
深忆病人
深忆病人 2021-02-07 07:00

I want to create an image what a web page looks like, e.g. create a small thumbnail of the html + images. it does not have to be perfect (e.g. flash /javascript rendering).

5条回答
  •  长情又很酷
    2021-02-07 07:37

    If you're interested in Java, maybe you could look at browser automation using Selenium-RC http://seleniumhq.com

    It's a little java server that you can install on the box and the program itself will execute remote commands in a web browser.

    Steps like (this is pseudo code by the way, I code my Selenium in php and I can't recall 100% of the specifics off the top of my head)

    selenium.location("http://foo.com")
    selenium.open("/folder/sub/bar.html")
    selenium.captureScreenshot("/tmp/" + this.getClass().getName() + "."
                                   + testMethodName + ".png");
    

    Actually, I just did a quick websearch for the exact syntax on that last one ... and this guy has a blog with what might actually be working code in java :) https://dev.youdevise.com/YDBlog/index.php?title=capture_screenshots_of_selenium_browser_&more=1&c=1&tb=1&pb=1

    There's also a number of websites that provide this service "cross browser and OS" I just can't recall what they are. Basically they've got a cloud of every single operating system and browser combination, and they log on with each machine, take a screen and store it on their site for you to come back to in a few hours when they're done.

    Ahh... another websearch and it's yours :) http://browsershots.org/

提交回复
热议问题