Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 478539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:42:07+00:00 2026-05-13T00:42:07+00:00

I want to get screenshots of a webpage in Python. For this I am

  • 0

I want to get screenshots of a webpage in Python. For this I am using http://github.com/AdamN/python-webkit2png/ .

    newArgs = ["xvfb-run", "--server-args=-screen 0, 640x480x24", sys.argv[0]]
    for i in range(1, len(sys.argv)):
        if sys.argv[i] not in ["-x", "--xvfb"]:
            newArgs.append(sys.argv[i])
    logging.debug("Executing %s" % " ".join(newArgs))
    os.execvp(newArgs[0], newArgs)

Basically calls xvfb-run with the correct args. But man xvfb says:

Note that the demo X clients used in the above examples will not exit on their own, so they will have to be killed before xvfb-run will exit.

So that means that this script will <????> if this whole thing is in a loop, (To get multiple screenshots) unless the X server is killed. How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:42:07+00:00Added an answer on May 13, 2026 at 12:42 am

    The documentation for os.execvp states:

    These functions all execute a new
    program, replacing the current
    process; they do not return. [..]

    So after calling os.execvp no other statement in the program will be executed. You may want to use subprocess.Popen instead:

    The subprocess module allows you to
    spawn new processes, connect to their
    input/output/error pipes, and obtain
    their return codes. This module
    intends to replace several other,
    older modules and functions, such as:

    Using subprocess.Popen, the code to run xlogo in the virtual framebuffer X server becomes:

    import subprocess
    xvfb_args = ['xvfb-run', '--server-args=-screen 0, 640x480x24', 'xlogo']
    process = subprocess.Popen(xvfb_args)
    

    Now the problem is that xvfb-run launches Xvfb in a background process. Calling process.kill() will not kill Xvfb (at least not on my machine…). I have been fiddling around with this a bit, and so far the only thing that works for me is:

    import os
    import signal
    import subprocess
    
    SERVER_NUM = 99  # 99 is the default used by xvfb-run; you can leave this out.
    
    xvfb_args = ['xvfb-run', '--server-num=%d' % SERVER_NUM,
                 '--server-args=-screen 0, 640x480x24', 'xlogo']
    subprocess.Popen(xvfb_args)
    
    # ... do whatever you want to do here...
    
    pid = int(open('/tmp/.X%s-lock' % SERVER_NUM).read().strip())
    os.kill(pid, signal.SIGINT)
    

    So this code reads the process ID of Xvfb from /tmp/.X99-lock and sends the process an interrupt. It works, but does yield an error message every now and then (I suppose you can ignore it, though). Hopefully somebody else can provide a more elegant solution. Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create website thumbnails (screenshots) using php. I have a dedicated server
I want to write a Simple P2P RDP Client and Server in Python. This
Hi, I could not manage to get where i want with my carousel. This
Is somebody using intellj in android projects here? I want to get screenshot realdevice
Can anybody help me in this? I want to get an screenshot from an
I want get the time used for a case so I can create an
I want get all of the Geom objects that are related to a certain
I want get as much as possible from Redis + Hiredis + libevent. I'm
I just want get a 2 dimension array of List in c#. In my
I want to get the top #nr_of_rows - (int)(#nr_of_rows / 10 - 1) of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.